Skip to content

Commit

Permalink
fix: fix cookie_token wrongly set issue (#269)
Browse files Browse the repository at this point in the history
Because

- #262

This commit

- fix cookie_token wrongly set issue, cause onboarding is not working (close #262)
  • Loading branch information
EiffelFly committed Sep 6, 2022
1 parent 19d1470 commit 7e25d9d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/components/onboarding/OnboardingForm/OnboardingForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,13 @@ const OnboardingForm = ({ user }: OnboardingFormProps) => {
if (!fieldValues.email || !fieldValues.companyName || !fieldValues.role)
return;

const token = uuidv4();
let token: string | undefined = undefined;

if (user && user.cookie_token && user.cookie_token !== "") {
token = user.cookie_token;
} else {
token = uuidv4();
}

const payload: Partial<User> = {
id: "local-user",
Expand All @@ -143,7 +149,7 @@ const OnboardingForm = ({ user }: OnboardingFormProps) => {
newsletter_subscription: fieldValues.newsletterSubscription
? fieldValues.newsletterSubscription
: false,
cookie_token: user ? user.cookie_token : token,
cookie_token: token,
};

setMessageBoxState(() => ({
Expand Down
1 change: 1 addition & 0 deletions src/pages/api/set-user-cookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
status: "ok",
});
} catch (err) {
console.log(err);
return res.status(500).end(String(err));
}
};
Expand Down

0 comments on commit 7e25d9d

Please sign in to comment.