clean9326
02/18/2023, 7:51 AMgetUserById in nestjs, it return me 
shell
[Nest] 1229  - 18/02/2023, 3:49:21 pm   ERROR [ExceptionsHandler] Initialisation not done. Did you forget to call the SuperTokens.init function?
Error: Initialisation not done. Did you forget to call the SuperTokens.init function?
    at Function.getInstanceOrThrowError (/Users/xxx/Desktop/projects/chatgpt-studywithme/chatgpt-studywithme/backend/node_modules/supertokens-node/lib/build/recipe/thirdpartyemailpassword/recipe.js:229:15)
    at Function.getUserById (/Users/bytedance/Desktop/projects/chatgpt-studywithme/chatgpt-studywithme/backend/node_modules/supertokens-node/lib/build/recipe/thirdpartyemailpassword/index.js:82:33)
    at UserController.getUserInfo (/Users/xxx/Desktop/projects/chatgpt-studywithme/chatgpt-studywithme/backend/src/user/user.controller.ts:15:52) 
my code is like:
ts
@Controller('user')
export class UserController {
  @Get()
  @UseGuards(new AuthGuard()) // For more information about this guard please read our NestJS guide.
  async getUserInfo(@Session() session: SessionContainer): Promise<User> {
    const userId = session.getUserId();
    // You can learn more about the `User` object over here https://github.com/supertokens/core-driver-interface/wiki
    const userInfo = await ThirdPartyEmailPassword.getUserById(userId);
    //....
    return userInfo;
  }
}rp_st
02/18/2023, 7:56 AMrp_st
02/18/2023, 7:57 AMrp_st
02/18/2023, 7:57 AMrp_st
02/18/2023, 8:00 AMclean9326
02/18/2023, 8:00 AMrp_st
02/18/2023, 8:00 AMclean9326
02/18/2023, 8:00 AMts
import { Inject, Injectable } from '@nestjs/common';
import supertokens from 'supertokens-node';
import { ConfigInjectionToken, AuthModuleConfig } from '../config.interface';
import * as SuperTokensConfig from '../../config';
@Injectable()
export class SupertokensService {
  constructor(@Inject(ConfigInjectionToken) private config: AuthModuleConfig) {
    supertokens.init({
      appInfo: config.appInfo,
      supertokens: {
        connectionURI: SuperTokensConfig.connectionUri,
        apiKey: SuperTokensConfig.apiKey,
      },
      recipeList: SuperTokensConfig.recipeList,
    });
  }
}
export const appInfo = {
  // Learn more about this on https://supertokens.com/docs/thirdpartypasswordless/appinfo
  appName: 'Studywithme',
  apiDomain: process.env.API_DOMAIN ?? 'http://localhost:3001',
  websiteDomain: process.env.WEBSITE_DOMAIN ?? 'http://localhost:3000',
  apiBasePath: '/auth',
  websiteBasePath: '/auth',
};
export const recipeList = [
  ThirdPartyPasswordless.init({
    providers: [
      // We have provided you with development keys which you can use for testing.
      // IMPORTANT: Please replace them with your own OAuth keys for production use.
      ThirdPartyPasswordless.Google({
        clientId: process.env.GOOGLE_ID,
        clientSecret: process.env.GOOGLE_SECRET,
      }),
      ThirdPartyPasswordless.Github({
        clientSecret: process.env.GITHUB_SECRET,
        clientId: process.env.GITHUB_ID,
      }),
    ],
    contactMethod: 'EMAIL_OR_PHONE',
    flowType: 'USER_INPUT_CODE_AND_MAGIC_LINK',
  }),
  Session.init(),
  Dashboard.init({
    apiKey: process.env.AUTH_API_KEY,
  }),
];rp_st
02/18/2023, 8:01 AMclean9326
02/18/2023, 8:01 AMclean9326
02/18/2023, 8:01 AMrp_st
02/18/2023, 8:01 AMgetUserIdclean9326
02/18/2023, 8:02 AMSuperTokens is an open source authentication solution offering features like: Different types of login: Email / password, Passwordless (OTP or Magic link based).
Powered by