mirror of
https://github.com/Steffo99/festa.git
synced 2024-12-22 22:54:22 +00:00
Move AuthContextProvider
to components/auth/provider
This commit is contained in:
parent
3c597158c8
commit
6829c7911a
2 changed files with 14 additions and 14 deletions
|
@ -1,7 +1,5 @@
|
||||||
import { Token, User } from "@prisma/client"
|
import { Token, User } from "@prisma/client"
|
||||||
import { default as React } from "react"
|
|
||||||
import { createStateContext } from "../../utils/stateContext"
|
import { createStateContext } from "../../utils/stateContext"
|
||||||
import { useLocalStorageAuthState } from "./storage"
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,15 +16,3 @@ export type AuthContextContents = Token & { user: User } | null
|
||||||
* Please note that the data containing in this context is not validated, and has to be validated by the server on every request.
|
* Please note that the data containing in this context is not validated, and has to be validated by the server on every request.
|
||||||
*/
|
*/
|
||||||
export const AuthContext = createStateContext<AuthContextContents>()
|
export const AuthContext = createStateContext<AuthContextContents>()
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Component which stores the login status using {@link useLocalStorageAuthState} and provides it to its children through a {@link AuthContext}.
|
|
||||||
*/
|
|
||||||
export function AuthContextProvider({ storageKey, children }: { storageKey: string, children: React.ReactNode }) {
|
|
||||||
return (
|
|
||||||
<AuthContext.Provider value={useLocalStorageAuthState(storageKey)}>
|
|
||||||
{children}
|
|
||||||
</AuthContext.Provider>
|
|
||||||
)
|
|
||||||
}
|
|
14
components/auth/provider.tsx
Normal file
14
components/auth/provider.tsx
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
import { AuthContext } from "./base";
|
||||||
|
import { useLocalStorageAuthState } from "./storage";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Component which stores the login status using {@link useLocalStorageAuthState} and provides it to its children through a {@link AuthContext}.
|
||||||
|
*/
|
||||||
|
export function AuthContextProvider({ storageKey, children }: { storageKey: string, children: React.ReactNode }) {
|
||||||
|
return (
|
||||||
|
<AuthContext.Provider value={useLocalStorageAuthState(storageKey)}>
|
||||||
|
{children}
|
||||||
|
</AuthContext.Provider>
|
||||||
|
)
|
||||||
|
}
|
Loading…
Reference in a new issue