Hi, Anyone know why when I implement the `getUserB...
# support-questions
c
Hi, Anyone know why when I implement the
getUserById
in
nestjs
, it return me
Copy code
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:
Copy code
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;
  }
}
r
hey @clean
Whats your supertokens.init look like?
on the backend
hey @clean let's talk in this thread.
c
ok
r
right. So the error is cause you have initialised ThirdPartyPasswordless, but you are using the ThirdPartyEmailPassword recipe in your API
c
Copy code
ts
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,
  }),
];
r
this.
c
oh, ok, so How can I get user's info when I using ThirdPartyPasswordless?
like email
r
That recipe should have the same function
getUserId
c
OK, I made it, thanks!
28 Views