Back

[SOLVED] React Native Appwrite SDK not working properly

  • 0
  • React Native
  • Auth
Devils
9 Dec, 2024, 20:25

So I'm trying to generate a unique ID using the ID.unique() and its generating properly, but its saying its longer than 36 characters but it isnt..

TypeScript
  const handleSignUp = async () => {
    if (password !== confirmPassword) {
      showAlert('error', 'Passwords do not match');
      return;
    }
  
    try {
      const UniqueId = api.ID.unique();
      console.log('Generated Unique ID:', UniqueId);
  
      const user = await api.account.create(UniqueId, email, password);
      const session = await api.account.createSession(email, password);
  
      await AsyncStorage.setItem('userId', user.$id);
      await AsyncStorage.setItem('sessionId', session.$id);
  
      showAlert('success', 'Account created successfully. Please verify your email.');
      navigation.navigate('EmailVerification');
    } catch (error) {
      console.error('Error during sign-up:', error);
  
      let alertMessage = 'Failed to sign up. Please try again.';
      if (error?.message?.includes('Invalid `email` param')) {
        alertMessage = 'Invalid email address, please try again.';
      } else if (error?.message?.includes('A user with the same id, email, or phone already exists')) {
        alertMessage = 'A user with that email already exists.';
      }
  
      showAlert('error', alertMessage);
    }
  };

My logs:

TypeScript
 (NOBRIDGE) LOG  Generated Unique ID: 6757507d003131dc71bf
 (NOBRIDGE) ERROR  Error during sign-up: [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]

If I'm not mistaken, the ID generated is exactly 20 characters LOL.

TL;DR
React Native developer is having issues with Appwrite SDK. They were using a wrong function. The unique ID generated was the correct length but still throwing an error. The problem was due to incorrect parameter usage in `api.account.create`. The issue was resolved after utilizing the correct parameters and following the documentation for `createSession()`. Solution: Ensure to utilize the correct parameters when calling `api.account.create()`.
Steven
9 Dec, 2024, 20:28

read the docs and params for createSession()

Devils
9 Dec, 2024, 20:31

Oh I didn't even notice I wasnt using that correctly.. I was thinking it was an issue with the actual creation of the account. :kekw: Thanks, solved my issue.

Devils
9 Dec, 2024, 20:32

[SOLVED] React Native Appwrite SDK not working properly

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