-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Justin Campbell
committed
Nov 13, 2020
1 parent
ca130f8
commit 50f03ec
Showing
3 changed files
with
47 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React, { useState, createContext, useContext } from "react"; | ||
|
||
|
||
|
||
const LoginContext = createContext(); | ||
const LoginSetterContext = createContext(); | ||
const TokenContext = createContext(); | ||
const TokenSetterContext = createContext(); | ||
|
||
export const useLogin = () => useContext(LoginContext); | ||
export const useLoginSetter = () => useContext(LoginSetterContext); | ||
export const useToken = () => useContext(TokenContext); | ||
export const useTokenSetter = () => useContext(TokenSetterContext); | ||
|
||
|
||
|
||
export default function AuthProvider({ children }) { | ||
const [loggedIn, setLoggedIn] = useState(false); | ||
const [token, setToken] = useState(null); | ||
|
||
return ( | ||
<LoginContext.Provider value={loggedIn}> | ||
<LoginSetterContext.Provider value={setLoggedIn}> | ||
<TokenContext.Provider value={token}> | ||
<TokenSetterContext.Provider value={setToken}> | ||
{children} | ||
</TokenSetterContext.Provider> | ||
</TokenContext.Provider> | ||
</LoginSetterContext.Provider> | ||
</LoginContext.Provider> | ||
); | ||
}; |
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,14 @@ | ||
AuthProvider | ||
|
||
Description | ||
|
||
--- | ||
|
||
```jsx | ||
import AuthProvider from "./AuthProvider"; | ||
|
||
<AuthProvider /> | ||
``` | ||
```jsx static | ||
<AuthProvider /> | ||
``` |
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 @@ | ||
export { default, useLogin, useLoginSetter, useToken, useTokenSetter } from "./AuthProvider"; |