feat: implement select session
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
import { useState, type FC, type ReactNode } from "react";
|
import { useCallback, useState, type FC, type ReactNode } from "react";
|
||||||
import { OAuthContext } from ".";
|
import { OAuthContext } from ".";
|
||||||
|
import { codeApi } from "@/api/code";
|
||||||
|
|
||||||
interface IOAuthProvider {
|
interface IOAuthProvider {
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
@ -13,6 +14,24 @@ export const OAuthProvider: FC<IOAuthProvider> = ({ children }) => {
|
|||||||
const [state, setState] = useState("");
|
const [state, setState] = useState("");
|
||||||
const [nonce, setNonce] = useState("");
|
const [nonce, setNonce] = useState("");
|
||||||
|
|
||||||
|
const selectSession = useCallback(
|
||||||
|
async (token: string) => {
|
||||||
|
if (active && redirectURI) {
|
||||||
|
const codeResponse = await codeApi(token, nonce);
|
||||||
|
|
||||||
|
console.log("gen code:", { codeResponse });
|
||||||
|
|
||||||
|
const params = new URLSearchParams({
|
||||||
|
code: codeResponse.code,
|
||||||
|
state,
|
||||||
|
});
|
||||||
|
|
||||||
|
window.location.replace(`${redirectURI}?${params.toString()}`);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[active, nonce, redirectURI, state]
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<OAuthContext.Provider
|
<OAuthContext.Provider
|
||||||
value={{
|
value={{
|
||||||
@ -28,6 +47,7 @@ export const OAuthProvider: FC<IOAuthProvider> = ({ children }) => {
|
|||||||
setScope,
|
setScope,
|
||||||
setState,
|
setState,
|
||||||
setNonce,
|
setNonce,
|
||||||
|
selectSession,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
Reference in New Issue
Block a user