feat: use oauth provider
This commit is contained in:
33
web/src/context/oauth/index.ts
Normal file
33
web/src/context/oauth/index.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import { createContext, useContext } from "react";
|
||||||
|
|
||||||
|
interface OAuthContextValues {
|
||||||
|
active: boolean;
|
||||||
|
clientID: string;
|
||||||
|
redirectURI: string;
|
||||||
|
scope: string[];
|
||||||
|
state: string;
|
||||||
|
nonce: string;
|
||||||
|
setActive: (state: boolean) => void;
|
||||||
|
setClientID: (id: string) => void;
|
||||||
|
setRedirectURI: (uri: string) => void;
|
||||||
|
setScope: (scopes: string[]) => void;
|
||||||
|
setState: (state: string) => void;
|
||||||
|
setNonce: (nonce: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const OAuthContext = createContext<OAuthContextValues>({
|
||||||
|
active: false,
|
||||||
|
clientID: "",
|
||||||
|
redirectURI: "",
|
||||||
|
scope: [],
|
||||||
|
state: "",
|
||||||
|
nonce: "",
|
||||||
|
setActive: () => {},
|
||||||
|
setClientID: () => {},
|
||||||
|
setRedirectURI: () => {},
|
||||||
|
setScope: () => {},
|
||||||
|
setState: () => {},
|
||||||
|
setNonce: () => {},
|
||||||
|
});
|
||||||
|
|
||||||
|
export const useOAuthContext = () => useContext(OAuthContext);
|
36
web/src/context/oauth/provider.tsx
Normal file
36
web/src/context/oauth/provider.tsx
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import { useState, type FC, type ReactNode } from "react";
|
||||||
|
import { OAuthContext } from ".";
|
||||||
|
|
||||||
|
interface IOAuthProvider {
|
||||||
|
children: ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const OAuthProvider: FC<IOAuthProvider> = ({ children }) => {
|
||||||
|
const [active, setActive] = useState(false);
|
||||||
|
const [clientID, setClientID] = useState("");
|
||||||
|
const [redirectURI, setRedirectURI] = useState("");
|
||||||
|
const [scope, setScope] = useState<string[]>([]);
|
||||||
|
const [state, setState] = useState("");
|
||||||
|
const [nonce, setNonce] = useState("");
|
||||||
|
|
||||||
|
return (
|
||||||
|
<OAuthContext.Provider
|
||||||
|
value={{
|
||||||
|
active,
|
||||||
|
clientID,
|
||||||
|
redirectURI,
|
||||||
|
scope,
|
||||||
|
state,
|
||||||
|
nonce,
|
||||||
|
setActive,
|
||||||
|
setClientID,
|
||||||
|
setRedirectURI,
|
||||||
|
setScope,
|
||||||
|
setState,
|
||||||
|
setNonce,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</OAuthContext.Provider>
|
||||||
|
);
|
||||||
|
};
|
@ -3,11 +3,14 @@ import App from "./App";
|
|||||||
|
|
||||||
import "./index.css";
|
import "./index.css";
|
||||||
import { DbProvider } from "./context/db/provider";
|
import { DbProvider } from "./context/db/provider";
|
||||||
|
import { OAuthProvider } from "./context/oauth/provider";
|
||||||
|
|
||||||
const root = document.getElementById("root")!;
|
const root = document.getElementById("root")!;
|
||||||
|
|
||||||
createRoot(root).render(
|
createRoot(root).render(
|
||||||
<DbProvider>
|
<DbProvider>
|
||||||
<App />
|
<OAuthProvider>
|
||||||
|
<App />
|
||||||
|
</OAuthProvider>
|
||||||
</DbProvider>
|
</DbProvider>
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user