fp/services/next/app/auth/[[...path]]/page.tsx

27 lines
874 B
TypeScript
Raw Permalink Normal View History

2024-11-05 19:48:21 +00:00
'use client';
import { useEffect, useState } from 'react';
import { redirectToAuth } from 'supertokens-auth-react';
import SuperTokens from 'supertokens-auth-react/ui';
import { ThirdPartyPreBuiltUI } from 'supertokens-auth-react/recipe/thirdparty/prebuiltui';
// import { PasswordlessPreBuiltUI } from 'supertokens-auth-react/recipe/passwordless/prebuiltui';
export default function Auth() {
// if the user visits a page that is not handled by us (like /auth/random), then we redirect them back to the auth page.
const [loaded, setLoaded] = useState(false);
useEffect(() => {
if (
SuperTokens.canHandleRoute([ThirdPartyPreBuiltUI]) === false
) {
redirectToAuth({ redirectBack: false });
} else {
setLoaded(true);
}
}, []);
if (loaded) {
return SuperTokens.getRoutingComponent([ThirdPartyPreBuiltUI]);
}
return null;
}