Back

invalid userID

  • 0
  • React Native
  • Auth
Ajaykumar
18 Jun, 2024, 08:21

AppwriteException: Invalid userId param: Parameter must contain at most 36 chars. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char

TL;DR
The developers are encountering an issue with an invalid `userID` parameter, despite the dashboard showing the user's creation. The log should be checked for an `id`. The error states that the `userID` parameter must contain a maximum of 36 characters and follow specific character guidelines. Solution: The `userID` parameter needs to adhere to the specified character requirements (a-z, A-Z, 0-9, period, hyphen, and underscore) and be within 36 characters. Make sure the `ID.unique()` method generates a valid `userID`.
Ajaykumar
18 Jun, 2024, 08:24
TypeScript
import { Client, Account, ID, Avatars, Databases } from "react-native-appwrite";

export const config = {
// All my tokens here 
}

// Init your React Native SDK
const client = new Client();

client
  .setEndpoint(config.endpoint) // Your Appwrite Endpoint
  .setProject(config.projectId) // Your project ID
  .setPlatform(config.platform); // Your application ID or bundle ID.

const account = new Account(client);
const avatars = new Avatars(client);
const databases = new Databases(client);

export const signIn = async (email, password) => {
  try {
    const session = await account.createSession(email, password);
    return session;
  } catch (error) {
    console.error(error);
    throw new Error(error);
  }
};

export const createUser = async (email, password, username) => {
  console.log({ id: ID.unique() });
  try {
    const newAccount = await account.create(
      ID.unique(),
      email,
      password,
      username
    );
    if (!newAccount) {
      throw new Error("Account creation failed");
    }
    const avatarUrl = avatars.getInitials(username);
    await signIn(email, password);

    const newUser = await databases.createDocument(
      config.databaseId,
      config.userCollectionId,
      ID.unique(),
      {
        accountId: newAccount.$id,
        email,
        username,
        avatar: avatarUrl,
      }
    );
    return newUser;
  } catch (error) {
    console.error(error);
    throw new Error(error);
  }
};
darShan
18 Jun, 2024, 08:33

what does the log print? An id or empty string?

Ajaykumar
18 Jun, 2024, 08:51

{"id": "667141550036c56bf019"}

Ajaykumar
18 Jun, 2024, 08:51

The ID is correct, and when I check the dashboard the user is created but it still give this exception

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