chore: codify React component style
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import type { FC, PropsWithChildren } from "react";
|
||||
import {
|
||||
createContext,
|
||||
useCallback,
|
||||
@@ -25,7 +26,6 @@ type AuthContextValue = {
|
||||
logout: () => Promise<void>;
|
||||
refresh: () => Promise<boolean>;
|
||||
};
|
||||
|
||||
const AuthContext = createContext<AuthContextValue | null>(null);
|
||||
|
||||
async function request(
|
||||
@@ -40,7 +40,8 @@ async function request(
|
||||
return data as Authentication;
|
||||
}
|
||||
|
||||
export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
const AuthProvider: FC<PropsWithChildren> = (props) => {
|
||||
const { children } = props;
|
||||
const queryClient = useQueryClient();
|
||||
const [user, setUser] = useState<User | null>(null);
|
||||
const [accessToken, setAccessToken] = useState<string | null>(null);
|
||||
@@ -138,10 +139,12 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
{children}
|
||||
</AuthContext>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export function useAuth() {
|
||||
function useAuth() {
|
||||
const context = useContext(AuthContext);
|
||||
if (!context) throw new Error("AuthProvider is required");
|
||||
return context;
|
||||
}
|
||||
|
||||
export { AuthProvider, useAuth };
|
||||
|
||||
Reference in New Issue
Block a user