From 8346c8510939fe213900a86687d42da79a65c81a Mon Sep 17 00:00:00 2001 From: "web@ppanel" Date: Tue, 21 Jan 2025 22:39:23 +0700 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(oauth):=20Refactor=20platform?= =?UTF-8?q?=20parameter=20handling=20and=20improve=20logout=20redirection?= =?UTF-8?q?=20logic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/oauth/[platform]/certification.tsx | 1 + apps/user/app/oauth/[platform]/page.tsx | 30 ++++++++++++------- apps/user/utils/common.ts | 3 +- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/apps/user/app/oauth/[platform]/certification.tsx b/apps/user/app/oauth/[platform]/certification.tsx index 3d21751..4fdc4c0 100644 --- a/apps/user/app/oauth/[platform]/certification.tsx +++ b/apps/user/app/oauth/[platform]/certification.tsx @@ -29,6 +29,7 @@ export default function Certification({ platform, children }: CertificationProps case 'google': return googleLoginCallback(body); case 'telegram': + // 回调参数是 # 开头的,需要去掉 return telegramLoginCallback(body); default: break; diff --git a/apps/user/app/oauth/[platform]/page.tsx b/apps/user/app/oauth/[platform]/page.tsx index f2c4528..947311c 100644 --- a/apps/user/app/oauth/[platform]/page.tsx +++ b/apps/user/app/oauth/[platform]/page.tsx @@ -5,25 +5,33 @@ import { getTranslations } from 'next-intl/server'; import Certification from './certification'; export async function generateStaticParams() { - return { - paths: [ - { params: { platform: 'telegram' } }, - { params: { platform: 'apple' } }, - { params: { platform: 'facebook' } }, - { params: { platform: 'google' } }, - { params: { platform: 'github' } }, - ], - fallback: false, - }; + return [ + { + platform: 'telegram', + }, + { + platform: 'apple', + }, + { + platform: 'facebook', + }, + { + platform: 'google', + }, + { + platform: 'github', + }, + ]; } export default async function Page({ - params: { platform }, + params, }: { params: { platform: string; }; }) { + const { platform } = await params; const t = await getTranslations('auth'); return ( diff --git a/apps/user/utils/common.ts b/apps/user/utils/common.ts index 2f36119..ec7fc6d 100644 --- a/apps/user/utils/common.ts +++ b/apps/user/utils/common.ts @@ -45,7 +45,8 @@ export function Logout() { if (!isBrowser()) return; cookies.remove('Authorization'); const pathname = location.pathname; - if (!['', '/', '/auth', '/tos', '/oauth'].includes(pathname)) { + console.log(pathname); + if (!['', '/', '/auth', '/tos'].includes(pathname) || !pathname.includes('/oauth/')) { setRedirectUrl(location.pathname); location.href = `/auth`; }