Skip to content

Commit

Permalink
feat: adjust sign-in page login flow (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnsonMao authored Oct 8, 2024
1 parent e25ee2f commit c420a58
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
12 changes: 12 additions & 0 deletions pages/signin/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 || '');
Expand Down
17 changes: 13 additions & 4 deletions utils/openLoginWindow.js
Original file line number Diff line number Diff line change
@@ -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);
});
}

0 comments on commit c420a58

Please sign in to comment.