review(front): refacto url-manager (#8861)
Replace https://github.com/twentyhq/twenty/pull/8855
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import { AtomEffect } from 'recoil';
|
||||
import omit from 'lodash.omit';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { cookieStorage } from '~/utils/cookie-storage';
|
||||
|
||||
@ -20,6 +21,20 @@ export const localStorageEffect =
|
||||
});
|
||||
};
|
||||
|
||||
const customCookieAttributeZodSchema = z.object({
|
||||
cookieAttributes: z.object({
|
||||
expires: z.union([z.number(), z.instanceof(Date)]).optional(),
|
||||
path: z.string().optional(),
|
||||
domain: z.string().optional(),
|
||||
secure: z.boolean().optional(),
|
||||
}),
|
||||
});
|
||||
|
||||
export const isCustomCookiesAttributesValue = (
|
||||
value: unknown,
|
||||
): value is { cookieAttributes: Cookies.CookieAttributes } =>
|
||||
customCookieAttributeZodSchema.safeParse(value).success;
|
||||
|
||||
export const cookieStorageEffect =
|
||||
<T>(
|
||||
key: string,
|
||||
@ -52,9 +67,7 @@ export const cookieStorageEffect =
|
||||
|
||||
const cookieAttributes = {
|
||||
...defaultAttributes,
|
||||
...(typeof newValue === 'object' &&
|
||||
'cookieAttributes' in newValue &&
|
||||
typeof newValue.cookieAttributes === 'object'
|
||||
...(isCustomCookiesAttributesValue(newValue)
|
||||
? newValue.cookieAttributes
|
||||
: {}),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user