diff --git a/web/app/account/oauth/authorize/page.tsx b/web/app/account/oauth/authorize/page.tsx index 67644e13b1..7948a8896d 100644 --- a/web/app/account/oauth/authorize/page.tsx +++ b/web/app/account/oauth/authorize/page.tsx @@ -7,7 +7,6 @@ import { RiMailLine, RiTranslate2, } from '@remixicon/react' -import dayjs from 'dayjs' import { useRouter, useSearchParams } from 'next/navigation' import * as React from 'react' import { useEffect, useRef } from 'react' @@ -29,7 +28,7 @@ import { function setItemWithExpiry(key: string, value: string, ttl: number) { const item = { value, - expiry: dayjs().add(ttl, 'seconds').unix(), + expiry: Math.floor((Date.now() + ttl * 1000) / 1000), } localStorage.setItem(key, JSON.stringify(item)) } diff --git a/web/app/page.tsx b/web/app/page.tsx index ddb49655d3..7f47a1455f 100644 --- a/web/app/page.tsx +++ b/web/app/page.tsx @@ -1,35 +1,5 @@ -'use client' +import { redirect } from 'next/navigation' -import Link from 'next/link' -import { useRouter } from 'next/navigation' -import { useEffect } from 'react' -import Loading from '@/app/components/base/loading' -import { OAUTH_AUTHORIZE_PENDING_KEY } from '@/app/account/oauth/authorize/constants' -import { getOAuthPendingRedirect } from '@/app/signin/utils/post-login-redirect' - -const Home = () => { - const router = useRouter() - - useEffect(() => { - const pendingRedirect = getOAuthPendingRedirect(OAUTH_AUTHORIZE_PENDING_KEY) - if (pendingRedirect) { - router.replace(pendingRedirect) - return - } - router.replace('/apps') - }, [router]) - - return ( -
- -
- -
- 🚀 -
-
-
- ) -} +const Home = () => redirect('/apps') export default Home diff --git a/web/app/signin/utils/post-login-redirect.ts b/web/app/signin/utils/post-login-redirect.ts index 5b455cd1d1..c5b976c643 100644 --- a/web/app/signin/utils/post-login-redirect.ts +++ b/web/app/signin/utils/post-login-redirect.ts @@ -1,19 +1,20 @@ import type { ReadonlyURLSearchParams } from 'next/navigation' -import dayjs from 'dayjs' import { OAUTH_AUTHORIZE_PENDING_KEY, REDIRECT_URL_KEY } from '@/app/account/oauth/authorize/constants' -export function getOAuthPendingRedirect(key: string): string | null { - const itemStr = localStorage.getItem(key) +const getCurrentUnixTimestamp = () => Math.floor(Date.now() / 1000) + +function getOAuthPendingRedirect(): string | null { + const itemStr = localStorage.getItem(OAUTH_AUTHORIZE_PENDING_KEY) if (!itemStr) return null try { const item = JSON.parse(itemStr) - localStorage.removeItem(key) + localStorage.removeItem(OAUTH_AUTHORIZE_PENDING_KEY) if (!item?.value) return null - return dayjs().unix() > item.expiry ? null : item.value + return getCurrentUnixTimestamp() > item.expiry ? null : item.value } catch { return null @@ -33,5 +34,5 @@ export const resolvePostLoginRedirect = (searchParams: ReadonlyURLSearchParams) } } - return getOAuthPendingRedirect(OAUTH_AUTHORIZE_PENDING_KEY) + return getOAuthPendingRedirect() }