mirror of
https://github.com/docmost/docmost.git
synced 2025-11-15 00:51:11 +10:00
add cookie duration
This commit is contained in:
@ -1,14 +1,17 @@
|
|||||||
import Cookies from "js-cookie";
|
import Cookies from "js-cookie";
|
||||||
import { createJSONStorage, atomWithStorage } from "jotai/utils";
|
import { createJSONStorage, atomWithStorage } from "jotai/utils";
|
||||||
import { ITokens } from '../types/auth.types';
|
import { ITokens } from "../types/auth.types";
|
||||||
|
|
||||||
|
|
||||||
const cookieStorage = createJSONStorage<ITokens>(() => {
|
const cookieStorage = createJSONStorage<ITokens>(() => {
|
||||||
return {
|
return {
|
||||||
getItem: () => Cookies.get("authTokens"),
|
getItem: () => Cookies.get("authTokens"),
|
||||||
setItem: (key, value) => Cookies.set(key, value),
|
setItem: (key, value) => Cookies.set(key, value, { expires: 30 }),
|
||||||
removeItem: (key) => Cookies.remove(key),
|
removeItem: (key) => Cookies.remove(key),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
export const authTokensAtom = atomWithStorage<ITokens | null>("authTokens", null, cookieStorage);
|
export const authTokensAtom = atomWithStorage<ITokens | null>(
|
||||||
|
"authTokens",
|
||||||
|
null,
|
||||||
|
cookieStorage,
|
||||||
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user