From 3d429d18ac14b2668ee8f396422ca45678d028c2 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Fri, 3 Feb 2023 19:35:48 -0800 Subject: [PATCH] Persist generated localId in localStorage --- pages/new/index.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pages/new/index.tsx b/pages/new/index.tsx index 69c8ae7d..a89e554a 100644 --- a/pages/new/index.tsx +++ b/pages/new/index.tsx @@ -1,6 +1,8 @@ import React, { useEffect, useState } from 'react' -import { useRouter } from 'next/router' +import { getCookie, setCookie } from 'cookies-next' +import { get, set } from 'local-storage' import { serverSideTranslations } from 'next-i18next/serverSideTranslations' +import { useRouter } from 'next/router' import { v4 as uuidv4 } from 'uuid' import clonedeep from 'lodash.clonedeep' @@ -19,7 +21,6 @@ import type { AxiosError } from 'axios' import type { NextApiRequest, NextApiResponse } from 'next' import type { PageContextObj, ResponseStatus } from '~types' import { GridType } from '~utils/enums' -import { setCookie } from 'cookies-next' interface Props { context?: PageContextObj @@ -59,6 +60,13 @@ const NewRoute: React.FC = ({ } }, [router.asPath]) + // Persist generated userId in storage + useEffect(() => { + const cookie = getCookie('account') + const data: AccountCookie = JSON.parse(cookie as string) + if (!get('userId') && data && !data.token) set('userId', data.userId) + }, []) + useEffect(() => { if (context && context.jobs && context.jobSkills) { appState.raids = context.raids