From ad566910035c7a16c716ed150e4645385a8d5310 Mon Sep 17 00:00:00 2001 From: yuwen Date: Sun, 14 Jul 2024 19:21:31 +0800 Subject: [PATCH] fix: use asPath property for token retrieval instead use query property - Replaced `useRouter().query` with `useRouter().asPath` to retrieve the `token` parameter - Changed implementation due to an issue where the token retrieved from `query` was not as expected --- pages/auth/token/[token].tsx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pages/auth/token/[token].tsx b/pages/auth/token/[token].tsx index 35c770a7..75531572 100644 --- a/pages/auth/token/[token].tsx +++ b/pages/auth/token/[token].tsx @@ -2,17 +2,15 @@ import { ReactElement, useEffect } from "react"; import { useRouter } from "next/router"; import { GetStaticProps, GetStaticPaths } from "next"; import { serverSideTranslations } from "next-i18next/serverSideTranslations"; - import { NextPageWithProps } from "@/pages/_app"; import useUser from "@/hooks/useUser"; const Token: NextPageWithProps = () => { - const { - query: { token }, - push, - } = useRouter(); - const { login } = useUser(); + const { push, asPath } = useRouter(); + const regex = /^\/auth\/token\/(.+)$/; + const token = asPath.match(regex)?.[1]; + const { login } = useUser(); useEffect(() => { if (token) { login(token as string);