Advertisement
Piotoru

problem with sign up super`tokens

Jun 1st, 2023 (edited)
850
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //NO SESSION FOR SIGN UP
  2.  
  3. Session.init({
  4.           override: {
  5.             functions: (originalImplementation) => {
  6.               return {
  7.                 ...originalImplementation,
  8.                 //empty session object for sign up
  9.                 //https://supertokens.com/docs/thirdpartyemailpassword/advanced-customizations/user-context
  10.                 createNewSession: async function (input) {
  11.                   if (input.userContext.isSignUp) {
  12.                     return {
  13.                       getAccessToken: () => '',
  14.                       getAccessTokenPayload: () => null,
  15.                       getExpiry: async () => -1,
  16.                       getHandle: () => '',
  17.                       getSessionData: async () => null,
  18.                       getTimeCreated: async () => -1,
  19.                       getUserId: () => '',
  20.                       // eslint-disable-next-line @typescript-eslint/no-empty-function
  21.                       revokeSession: async () => {},
  22.                       // eslint-disable-next-line @typescript-eslint/no-empty-function
  23.                       updateAccessTokenPayload: async () => {},
  24.                       // eslint-disable-next-line @typescript-eslint/no-empty-function
  25.                       updateSessionData: async () => {},
  26.                       // eslint-disable-next-line @typescript-eslint/no-empty-function
  27.                       mergeIntoAccessTokenPayload: async () => {},
  28.                       // eslint-disable-next-line @typescript-eslint/no-empty-function
  29.                       assertClaims: async () => {},
  30.                       // eslint-disable-next-line @typescript-eslint/no-empty-function
  31.                       fetchAndSetClaim: async () => {},
  32.                       getClaimValue: async () => undefined,
  33.                       // eslint-disable-next-line @typescript-eslint/no-empty-function
  34.                       setClaimValue: async () => {},
  35.                       // eslint-disable-next-line @typescript-eslint/no-empty-function
  36.                       removeClaim: async () => {},
  37.                     };
  38.                   }
  39.                   return originalImplementation.createNewSession(input);
  40.                 },
  41.               };
  42.             },
  43.           },
  44.         }),
  45.  
  46.  
  47. //401 ERROR FOR USERS
  48.  
  49. @Get()
  50.   @UseGuards(new AuthGuard())
  51.   async users(@Query('queryData') queryData: QueryDto) {
  52.     const getCache: UserDto[] = await this.cacheManager.get('users');
  53.  
  54.     const { orderBy, limit, where, cursor } = queryData;
  55.     if (!!getCache) {
  56.       return getCache;
  57.     } else {
  58.       const { order, whereElements }: SortType = await queriesTransformation(
  59.         true,
  60.         orderBy,
  61.         where,
  62.       );
  63.  
  64.       const firstResults = await this.usersService.findAllUsers({
  65.         take: parseInt(limit) || undefined,
  66.         orderBy: order || undefined,
  67.         where: whereElements || undefined,
  68.       });
  69.  
  70.       const firstNextData: UserDto[] = [];
  71.       const nextData: UserDto[] = [];
  72.  
  73.       if (!!cursor) {
  74.         const nextResults = await this.usersService.findAllUsers({
  75.           take: parseInt(limit) || undefined,
  76.           orderBy: order || undefined,
  77.           skip: 1,
  78.           cursor: {
  79.             pseudonym: cursor,
  80.           },
  81.           where: whereElements || undefined,
  82.         });
  83.  
  84.         if (nextResults.length > 0) {
  85.           if (firstNextData.length === 0) {
  86.             firstNextData.concat(firstResults, nextResults);
  87.             await this.cacheManager.set('users', firstNextData);
  88.             return firstNextData;
  89.           }
  90.  
  91.           if (nextData.length === 0) {
  92.             nextData.concat(firstNextData, nextResults);
  93.             await this.cacheManager.set('users', nextData);
  94.             return nextData;
  95.           }
  96.  
  97.           nextData.concat(nextResults);
  98.           await this.cacheManager.set('users', nextData);
  99.           return nextData;
  100.         } else {
  101.           return allContent;
  102.         }
  103.       } else {
  104.         await this.cacheManager.set('users', firstResults);
  105.         return firstResults;
  106.       }
  107.     }
  108.   }
  109.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement