Skip to content

Commit

Permalink
fix: use asPath property for token retrieval instead use query property
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
Yuwen-ctw committed Jul 14, 2024
1 parent fc1ff77 commit ad56691
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions pages/auth/token/[token].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ad56691

Please sign in to comment.