Funnel point

This commit is contained in:
Manav Rathi 2024-07-01 10:15:08 +05:30
parent 05e7a998e2
commit 4acd17f06b
No known key found for this signature in database
2 changed files with 16 additions and 0 deletions

View File

@ -1,6 +1,8 @@
// TODO: This file belongs to the accounts package
import { z } from "zod";
// TODO: During login the only field present is email. Which makes this
// optionality indicated by these types incorrect.
const LocalUser = z.object({
/** The user's ID. */
id: z.number(),

View File

@ -1,4 +1,5 @@
import log from "@/next/log";
import { removeKV, setKV } from "packages/next/kv";
export enum LS_KEYS {
USER = "user",
@ -46,3 +47,16 @@ export const getData = (key: LS_KEYS) => {
};
export const clearData = () => localStorage.clear();
// TODO: Migrate this to `local-user.ts`, with (a) more precise optionality
// indication of the constituent fields, (b) moving any fields that need to be
// accessed from web workers to KV DB.
//
// Creating a new function here to act as a funnel point.
export const setLSUser = (user: object) => {
const token = user["token"];
token && typeof token == "string"
? setKV("token", token)
: removeKV("token");
setData(LS_KEYS.USER, user);
};