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