-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
worked on evently admin panel authorization
login signup secure route done
- Loading branch information
1 parent
e597ebb
commit a548910
Showing
6 changed files
with
351 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* eslint-disable prettier/prettier */ | ||
import React, { createContext, useState } from "react"; | ||
import Cookies from "js-cookie"; | ||
import PropTypes from 'prop-types'; | ||
|
||
// Create the context | ||
const AuthContext = createContext(); | ||
|
||
// Create a provider component | ||
export const AuthProvider = ({ children }) => { | ||
const [authenticated, setAuthenticated] = useState( | ||
!!Cookies.get("authorizationAdmin") | ||
); | ||
|
||
// console.log("tokennn:", Cookies.get("authorizationAdmin")); | ||
|
||
const login = () => { | ||
setAuthenticated(true); | ||
}; | ||
|
||
const logout = () => { | ||
Cookies.remove("authorizationAdmin"); | ||
setAuthenticated(false); | ||
}; | ||
console.log("authenticated...authenticated",authenticated) | ||
|
||
return ( | ||
<AuthContext.Provider value={{ authenticated, login, logout }}> | ||
{children} | ||
</AuthContext.Provider> | ||
); | ||
}; | ||
|
||
AuthProvider.propTypes = { | ||
children: PropTypes.node.isRequired, | ||
}; | ||
|
||
export default AuthContext; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
/* eslint-disable prettier/prettier */ | ||
import React from 'react' | ||
import { createRoot } from 'react-dom/client' | ||
import { Provider } from 'react-redux' | ||
import 'core-js' | ||
|
||
import App from './App' | ||
import store from './store' | ||
import { AuthProvider } from './authContext' | ||
|
||
createRoot(document.getElementById('root')).render( | ||
<Provider store={store}> | ||
<AuthProvider> | ||
<App /> | ||
</Provider>, | ||
</AuthProvider> | ||
</Provider> | ||
) |
Oops, something went wrong.