Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //NO SESSION FOR SIGN UP
- Session.init({
- override: {
- functions: (originalImplementation) => {
- return {
- ...originalImplementation,
- //empty session object for sign up
- //https://supertokens.com/docs/thirdpartyemailpassword/advanced-customizations/user-context
- createNewSession: async function (input) {
- if (input.userContext.isSignUp) {
- return {
- getAccessToken: () => '',
- getAccessTokenPayload: () => null,
- getExpiry: async () => -1,
- getHandle: () => '',
- getSessionData: async () => null,
- getTimeCreated: async () => -1,
- getUserId: () => '',
- // eslint-disable-next-line @typescript-eslint/no-empty-function
- revokeSession: async () => {},
- // eslint-disable-next-line @typescript-eslint/no-empty-function
- updateAccessTokenPayload: async () => {},
- // eslint-disable-next-line @typescript-eslint/no-empty-function
- updateSessionData: async () => {},
- // eslint-disable-next-line @typescript-eslint/no-empty-function
- mergeIntoAccessTokenPayload: async () => {},
- // eslint-disable-next-line @typescript-eslint/no-empty-function
- assertClaims: async () => {},
- // eslint-disable-next-line @typescript-eslint/no-empty-function
- fetchAndSetClaim: async () => {},
- getClaimValue: async () => undefined,
- // eslint-disable-next-line @typescript-eslint/no-empty-function
- setClaimValue: async () => {},
- // eslint-disable-next-line @typescript-eslint/no-empty-function
- removeClaim: async () => {},
- };
- }
- return originalImplementation.createNewSession(input);
- },
- };
- },
- },
- }),
- //401 ERROR FOR USERS
- @Get()
- @UseGuards(new AuthGuard())
- async users(@Query('queryData') queryData: QueryDto) {
- const getCache: UserDto[] = await this.cacheManager.get('users');
- const { orderBy, limit, where, cursor } = queryData;
- if (!!getCache) {
- return getCache;
- } else {
- const { order, whereElements }: SortType = await queriesTransformation(
- true,
- orderBy,
- where,
- );
- const firstResults = await this.usersService.findAllUsers({
- take: parseInt(limit) || undefined,
- orderBy: order || undefined,
- where: whereElements || undefined,
- });
- const firstNextData: UserDto[] = [];
- const nextData: UserDto[] = [];
- if (!!cursor) {
- const nextResults = await this.usersService.findAllUsers({
- take: parseInt(limit) || undefined,
- orderBy: order || undefined,
- skip: 1,
- cursor: {
- pseudonym: cursor,
- },
- where: whereElements || undefined,
- });
- if (nextResults.length > 0) {
- if (firstNextData.length === 0) {
- firstNextData.concat(firstResults, nextResults);
- await this.cacheManager.set('users', firstNextData);
- return firstNextData;
- }
- if (nextData.length === 0) {
- nextData.concat(firstNextData, nextResults);
- await this.cacheManager.set('users', nextData);
- return nextData;
- }
- nextData.concat(nextResults);
- await this.cacheManager.set('users', nextData);
- return nextData;
- } else {
- return allContent;
- }
- } else {
- await this.cacheManager.set('users', firstResults);
- return firstResults;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement