diff --git a/pages/signin/index.jsx b/pages/signin/index.jsx index f57a16a..6a92101 100644 --- a/pages/signin/index.jsx +++ b/pages/signin/index.jsx @@ -16,6 +16,7 @@ import SEOConfig from '@/shared/components/SEO'; import Navigation from '@/shared/components/Navigation_v2'; import Footer from '@/shared/components/Footer_v2'; import styled from '@emotion/styled'; +import { getRedirectionStorage } from '@/utils/storage'; export const HomePageWrapper = styled.div` --section-height: calc(100vh - 80px); @@ -95,6 +96,17 @@ function EditPage() { } }, [id, token]); + useEffect(() => { + if (id && token) { + getRedirectionStorage().set(`/signin?id=${id}`); + window.opener?.postMessage( + { isLogin: true, id, token }, + window.location.origin, + ); + window.close(); + } + }, [id, token]); + useEffect(() => { setBirthDay(userBirthDay ? dayjs(userBirthDay) : dayjs()); setGender(userGender || ''); diff --git a/utils/openLoginWindow.js b/utils/openLoginWindow.js index 5daa39d..3e0ea4c 100644 --- a/utils/openLoginWindow.js +++ b/utils/openLoginWindow.js @@ -1,15 +1,24 @@ import { getRedirectionStorage } from './storage'; export default function openLoginWindow( - redirection = '/', + redirection = '', target = '/login/popup', ) { const width = 520; const height = 760; - const left = (window.innerWidth - width) / 2; - const top = (window.innerHeight - height) / 2; + const left = (window.screen.width - width) / 2; + const top = (window.screen.height - height) / 2; const features = `left=${left},top=${top},width=${width},height=${height}`; const loginWindow = window.open('', '_blank', features); - getRedirectionStorage().set(redirection); + if (redirection) getRedirectionStorage().set(redirection); if (loginWindow) loginWindow.location = target; + + return new Promise((resolve) => { + const loop = setInterval(() => { + if (loginWindow.closed) { + clearInterval(loop); + resolve(); + } + }, 500); + }); }