diff --git a/src/payloads/session.ts b/src/payloads/session.ts index a66158be..b376281d 100644 --- a/src/payloads/session.ts +++ b/src/payloads/session.ts @@ -22,39 +22,46 @@ export const FIMSToken = () => { return mFIMSToken; }; -const tokensObject: PublicSession = { +const generateSessionTokens = (): PublicSession => ({ spidLevel: "https://www.spid.gov.it/SpidL2" as SpidLevel, walletToken: getToken("AAAAAAAAAAAAA1"), myPortalToken: getToken("AAAAAAAAAAAAA2"), bpdToken: getToken("AAAAAAAAAAAAA3"), zendeskToken: getToken("AAAAAAAAAAAAA4"), fimsToken: FIMSToken() -}; +}); -const generateSessionTokens = (): PublicSession => tokensObject; +// eslint-disable-next-line functional/no-let +let customSession: PublicSession | undefined; export const generateCustomObjectSessionTokens = ( tokenString: string | ParsedQs | string[] | ParsedQs[] ): Partial => { // If no tokenString is provided, return the entire tokensObject if (!tokenString || typeof tokenString !== "string") { - return tokensObject; + customSession = generateSessionTokens(); + } else { + // Parse the tokenString to extract the tokens + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const tokenKeys: Array = tokenString + .replace(/[()]/g, "") // Remove parentheses + .split(",") // Split by comma + .filter( + (key: string): key is keyof PublicSession => + key in generateSessionTokens() + ); // Ensure keys are valid + // Return a filtered object based on tokenKeys + const filteredEntries = tokenKeys.map(key => [ + key, + generateSessionTokens()[key] + ]); + customSession = Object.fromEntries( + filteredEntries + ) as Partial; } - - // Parse the tokenString to extract the tokens - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const tokenKeys: Array = tokenString - .replace(/[()]/g, "") // Remove parentheses - .split(",") // Split by comma - .filter((key: string): key is keyof PublicSession => key in tokensObject); // Ensure keys are valid - // Return a filtered object based on tokenKeys - const filteredEntries = tokenKeys.map(key => [key, tokensObject[key]]); - return Object.fromEntries(filteredEntries) as Partial; + return customSession; }; -// eslint-disable-next-line functional/no-let -let customSession: PublicSession | undefined; - export const createOrRefreshSessionTokens = () => { customSession = generateSessionTokens(); };