Back

Email OTP Auth with appwrite-node SDK.

  • 0
  • Self Hosted
  • Auth
StarckisBack
13 Nov, 2024, 12:30

Hello, I am trying to setup a email otp auth for my react application via nestjs backend which is using appwrite-node sdk.

Here, when i am triggering createEmailToken with sessionClient its giving a empty secret whereas with adminClient it was giving a secret otp.

Also please let me know how to verify otp and also if we can access the email templates from node sdk.

Here's my code -

TypeScript
    this.sessionClient = new Client()
      .setEndpoint(this.configService.get<string>('APPWRITE_ENDPOINT'))
      .setProject(this.configService.get<string>('APPWRITE_PROJECT_ID'))
      .setSelfSigned(true);

    this.sessionAccount = new Account(this.sessionClient);

async emailOtp(email: string) {
    try {
      const result = await this.sessionAccount.createEmailToken(
        ID.unique(),
        email,
      );
      console.log('Inside emailOtp', result);
      return {
        message: 'Email OTP sent',
        userId: result.userId,
        email: email,
      };
    } catch (error) {
      this.logger.error('Failed to create email token:', error);
      throw new HttpException(
        'Failed to create email token',
        HttpStatus.BAD_REQUEST,
      );
    }
  }
TL;DR
Developers are setting up email OTP authentication for a React app using NestJS backend with appwrite-node SDK. They are encountering an issue where createEmailToken with sessionClient gives an empty secret, but with adminClient, it provides a secret OTP. Additionally, developers need assistance with verifying the OTP and accessing email templates from the Node SDK.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more