This commit is contained in:
hailin 2025-03-12 13:32:21 +08:00
parent c1cd9062f6
commit a11069e7a2
1 changed files with 39 additions and 39 deletions

View File

@ -10,45 +10,45 @@ import { OAuthButton } from "../oauth-button";
//type OAuthStrategy = 'oauth_google' | 'oauth_github'; //type OAuthStrategy = 'oauth_google' | 'oauth_github';
export function OAuthSignIn() { export function OAuthSignIn() {
const [isLoading, setIsLoading] = React.useState<OAuthStrategy | null>(null); // const [isLoading, setIsLoading] = React.useState<OAuthStrategy | null>(null);
const { signIn, isLoaded: signInLoaded } = useSignIn(); // const { signIn, isLoaded: signInLoaded } = useSignIn();
const oauthSignIn = async (provider: OAuthStrategy) => { // const oauthSignIn = async (provider: OAuthStrategy) => {
if (!signInLoaded) { // if (!signInLoaded) {
return null; // return null;
} // }
try { // try {
setIsLoading(provider); // setIsLoading(provider);
await signIn.authenticateWithRedirect({ // await signIn.authenticateWithRedirect({
strategy: provider, // strategy: provider,
redirectUrl: "/auth/sso-callback", // redirectUrl: "/auth/sso-callback",
redirectUrlComplete: "/app/apis", // redirectUrlComplete: "/app/apis",
}); // });
} catch (err) { // } catch (err) {
console.error(err); // console.error(err);
setIsLoading(null); // setIsLoading(null);
toast.error((err as Error).message); // toast.error((err as Error).message);
} // }
}; // };
return ( // return (
<div className="flex flex-col gap-2"> // <div className="flex flex-col gap-2">
<OAuthButton onClick={() => oauthSignIn("oauth_github")}> // <OAuthButton onClick={() => oauthSignIn("oauth_github")}>
{isLoading === "oauth_github" ? ( // {isLoading === "oauth_github" ? (
<Loading className="w-6 h-6" /> // <Loading className="w-6 h-6" />
) : ( // ) : (
<IconGitHub className="w-6 h-6" /> // <IconGitHub className="w-6 h-6" />
)} // )}
GitHub // GitHub
</OAuthButton> // </OAuthButton>
<OAuthButton onClick={() => oauthSignIn("oauth_google")}> // <OAuthButton onClick={() => oauthSignIn("oauth_google")}>
{isLoading === "oauth_google" ? ( // {isLoading === "oauth_google" ? (
<Loading className="w-6 h-6" /> // <Loading className="w-6 h-6" />
) : ( // ) : (
<IconGoogle className="w-6 h-6" /> // <IconGoogle className="w-6 h-6" />
)} // )}
Google // Google
</OAuthButton> // </OAuthButton>
</div> // </div>
); // );
} }