You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.2 KiB
49 lines
1.2 KiB
'use client'
|
|
|
|
import { Routes } from '@/config/routes'
|
|
import { toast } from '@/hooks/use-toast'
|
|
import { CredentialResponse, GoogleLogin } from '@react-oauth/google'
|
|
import { signIn } from 'next-auth/react'
|
|
import { useRouter, useSearchParams } from 'next/navigation'
|
|
|
|
export default function LoginWithGoogle() {
|
|
const router = useRouter()
|
|
const searchParams = useSearchParams()
|
|
const redirect = searchParams.get('redirect')
|
|
|
|
const onGoogleLoginSuccess = async (
|
|
credentialResponse: CredentialResponse
|
|
) => {
|
|
toast({
|
|
title: 'Success',
|
|
description: 'You are logged in with Google',
|
|
variant: 'default',
|
|
})
|
|
await signIn('google-id-token-login', {
|
|
redirect: true,
|
|
callbackUrl: redirect ? decodeURIComponent(redirect) : Routes.dashboard,
|
|
idToken: credentialResponse.credential,
|
|
})
|
|
}
|
|
|
|
const onGoogleLoginError = () => {
|
|
toast({
|
|
title: 'Error',
|
|
description: 'Something went wrong',
|
|
variant: 'destructive',
|
|
})
|
|
}
|
|
return (
|
|
<GoogleLogin
|
|
onSuccess={onGoogleLoginSuccess}
|
|
onError={onGoogleLoginError}
|
|
useOneTap={true}
|
|
width={'100%'}
|
|
size='large'
|
|
shape='pill'
|
|
locale='en'
|
|
theme='outline'
|
|
text='continue_with'
|
|
/>
|
|
)
|
|
}
|