-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import {Loader2} from 'lucide-react'; | ||
import {useEffect} from 'react'; | ||
import {useNavigate} from 'react-router-dom'; | ||
import {signInAndUp} from 'supertokens-web-js/recipe/thirdparty'; | ||
import {Card, CardContent} from './components/ui/card'; | ||
|
||
const CallbackHandler = () => { | ||
const navigate = useNavigate(); | ||
|
||
useEffect(() => { | ||
async function handleGithubCallback() { | ||
try { | ||
const response = await signInAndUp(); | ||
|
||
if (response.status === 'OK') { | ||
console.log('User is: ', response.user); | ||
if ( | ||
response.createdNewRecipeUser && | ||
response.user.loginMethods.length === 1 | ||
) { | ||
// Sign-up successful | ||
// You can perform any additional sign-up logic here | ||
} else { | ||
// Sign-in successful | ||
// You can perform any additional sign-in logic here | ||
} | ||
navigate('/'); // Redirect to home or desired page | ||
} else if (response.status === 'SIGN_IN_UP_NOT_ALLOWED') { | ||
// Display a user-friendly error message | ||
window.alert(response.reason); | ||
} else { | ||
// Handle cases where no email is provided by the third-party provider | ||
window.alert( | ||
'No email provided by social login. Please use another form of login.' | ||
); | ||
navigate('/auth'); // Redirect back to the login page | ||
} | ||
} catch (err) { | ||
console.log('Github error is: ', err); | ||
if (err.isSuperTokensGeneralError === true) { | ||
// Handle custom error messages sent from your API | ||
// window.alert(err.message); | ||
} else { | ||
// window.alert(err.message); | ||
} | ||
} | ||
} | ||
|
||
handleGithubCallback(); | ||
}, [navigate]); | ||
|
||
return ( | ||
<div className="flex min-h-screen items-center justify-center bg-gray-50 p-4"> | ||
<Card className="w-full max-w-[400px] p-6"> | ||
<CardContent className="space-y-6"> | ||
{/*<div className="flex justify-center">*/} | ||
{/* <Image*/} | ||
{/* src={logo}*/} | ||
{/* alt="Logo"*/} | ||
{/* className="object-cover cursor-pointer"*/} | ||
{/* width={150}*/} | ||
{/* height={50}*/} | ||
{/* />*/} | ||
{/*</div>*/} | ||
<div className="space-y-2 text-center"> | ||
<h1 className="text-2xl font-semibold tracking-tight"> | ||
Authenticating | ||
</h1> | ||
<p className="text-sm text-muted-foreground"> | ||
Please wait while we process your login... | ||
</p> | ||
</div> | ||
<div className="flex justify-center"> | ||
<Loader2 className="w-12 h-12 text-[#74BE9B] animate-spin" /> | ||
</div> | ||
</CardContent> | ||
</Card> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CallbackHandler; |