"If you weren't redirected, click here"

This commit is contained in:
Stan Wohlwend 2024-05-21 09:56:08 +02:00
parent 8e0eb8f472
commit 221341a732
2 changed files with 15 additions and 2 deletions

View File

@ -9,18 +9,28 @@ export default function OAuthCallback () {
const app = useStackApp();
const called = useRef(false);
const [error, setError] = useState<unknown>(null);
const [showRedirectLink, setShowRedirectLink] = useState(false);
useEffect(() => runAsynchronously(async () => {
if (called.current) return;
called.current = true;
let hasRedirected = false;
try {
await app.callOAuthCallback();
hasRedirected = await app.callOAuthCallback();
} catch (e: any) {
setError(e);
}
if (!hasRedirected) {
await app.redirectToSignIn();
}
}), []);
useEffect(() => {
setTimeout(() => setShowRedirectLink(true), 3000);
}, []);
return <MessageCard title='Redirecting...' fullPage>
{showRedirectLink ? <p>If you are not redirected automatically, <a href={app.urls.home}>click here</a>.</p> : null}
{error ? <div>
<p>Something went wrong while processing the OAuth callback:</p>
<pre>{JSON.stringify(error, null, 2)}</pre>

View File

@ -745,10 +745,13 @@ class _StackClientAppImpl<HasTokenStore extends boolean, ProjectId extends strin
if (result) {
if (result.newUser) {
await this.redirectToAfterSignUp({ replace: true });
return true;
} else {
await this.redirectToAfterSignIn({ replace: true });
return true;
}
}
return false;
}
protected async _signOut(tokenStore: TokenStore): Promise<void> {
@ -1656,7 +1659,7 @@ export type StackClientApp<HasTokenStore extends boolean = boolean, ProjectId ex
signInWithOAuth(provider: string): Promise<void>,
signInWithCredential(options: { email: string, password: string }): Promise<KnownErrors["EmailPasswordMismatch"] | undefined>,
signUpWithCredential(options: { email: string, password: string }): Promise<KnownErrors["UserEmailAlreadyExists"] | KnownErrors["PasswordRequirementsNotMet"] | undefined>,
callOAuthCallback(): Promise<void>,
callOAuthCallback(): Promise<boolean>,
sendForgotPasswordEmail(email: string): Promise<KnownErrors["UserNotFound"] | undefined>,
sendMagicLinkEmail(email: string): Promise<KnownErrors["RedirectUrlNotWhitelisted"] | undefined>,
resetPassword(options: { code: string, password: string }): Promise<KnownErrors["PasswordResetError"] | undefined>,