1
Fork 0
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:
Steffo 2022-07-17 03:32:36 +02:00
parent 3c597158c8
commit 6829c7911a
Signed by: steffo
GPG key ID: 6965406171929D01
2 changed files with 14 additions and 14 deletions

View file

@ -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>
)
}

View 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>
)
}