Back

Issue with Email Verification Failing in Appwrite Cloud Function

  • 0
  • Flutter
  • Functions
  • Auth
Rahul
4 Oct, 2024, 21:24

I have implemented an email verification feature using Appwrite, but the verification process fails when the user clicks the email link. Here's what I'm working with:

Dart Code (Send Verification Email)

TypeScript
Future<void> sendEmailAndPasswordVerificationLink(String userId, String secret) async {
  final token = await account.createVerification(url: 'http://67004d383faf2a735120.appwrite.global');
  print(token.toMap());
}

Appwrite Cloud Function

TypeScript
import { Client, Users, Account } from 'node-appwrite';

export default async ({ req, res, log, error }) => {
  const client = new Client()
    .setEndpoint(process.env.APPWRITE_FUNCTION_API_ENDPOINT)
    .setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID)
    .setKey(req.headers['x-appwrite-key'] ?? '');

  const account = new Account(client);
  const user = new Users(client);

  try {
    const { userId, secret } = req.query;
    if (!userId || !secret) {
      throw new Error('Missing userId or secret in query parameters');
    }

    const response = await account.updateVerification(userId, secret);
    log(req.query);
    return res.json({
      success: true,
      message: 'User verification successful',
      data: response,
    });
  } catch (err) {
    log(req.query);
    return res.json({
      success: false,
      message: 'User verification failed',
      error: err.message,
    });
  }
};

Problem:

I am successfully receiving the email, but when I click the verification link, the following error occurs:

TypeScript
{
  "success": false,
  "message": "User verification failed",
  "error": "app.66f7536e00244af68e02@service.cloud.appwrite.io (role: applications) missing scope (public)"
}

It seems like there is a missing scope or permission issue, but I'm unsure how to resolve this. Could someone help me understand what this error means and how I can fix it?

TL;DR
Developers are experiencing an issue with email verification in an Appwrite Cloud Function due to a missing scope or permission error. The error message points to a specific service lacking necessary permissions. To fix this, the developers need to ensure that the appropriate scope (public) is granted to the specified service (app.66f7536e00244af68e02@service.cloud.appwrite.io).
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