-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
auth: Show Google Oauth as a popup window
This way, the current page's state will remain the same, as the page won't be reloaded
- Loading branch information
1 parent
d7973d0
commit 5f3ef5b
Showing
6 changed files
with
61 additions
and
18 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
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
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
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
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,28 @@ | ||
import Google from 'common/icons/Google' | ||
import { Button } from '@mui/material' | ||
import { useTranslation } from 'react-i18next' | ||
|
||
const onGoogleLogin = () => { | ||
const url = `/google-signin` | ||
const POPUP_WIDTH = 500 | ||
const POPUP_HEIGHT = 550 | ||
const y = window.outerHeight / 2 + window.screenY - POPUP_HEIGHT / 2 | ||
const x = window.outerWidth / 2 + window.screenX - POPUP_WIDTH / 2 | ||
|
||
const newWindow = window.open( | ||
url, | ||
'_blank', | ||
`width=${POPUP_WIDTH},height=${POPUP_HEIGHT} top=${y} left=${x} popup`, | ||
) | ||
newWindow?.focus() | ||
} | ||
|
||
export default function GoogleSignInButton({ ...props }) { | ||
const { t } = useTranslation() | ||
|
||
return ( | ||
<Button variant="outlined" fullWidth onClick={onGoogleLogin} {...props}> | ||
<Google /> {t('nav.login-with')} Google | ||
</Button> | ||
) | ||
} |
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,15 @@ | ||
import { signIn, useSession } from 'next-auth/react' | ||
import { useEffect } from 'react' | ||
|
||
const GoogleSignIn = () => { | ||
const { data: session, status } = useSession() | ||
|
||
useEffect(() => { | ||
if (!session) signIn('google') | ||
if (session) window.close() | ||
}, [session, status]) | ||
|
||
return null | ||
} | ||
|
||
export default GoogleSignIn |