Back

ErrorInvalid `userId` param: Parameter must contain at most 36 chars. Valid chars are a-z, A-Z, 0-9

  • 0
  • React Native
YmajineUnBan !
19 Aug, 2024, 21:05

hello i'm trying to make a login / register page but i have this error

TypeScript
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.

this is my code

Login.js

TypeScript
// LoginScreen.js
import React, { useState } from 'react';
import { View, Text, TextInput, Button, Alert } from 'react-native';
import { account } from '../../lib/AppWrite'; // Assurez-vous que l'objet account est correctement importé
import { useNavigation } from '@react-navigation/native';

export default function LoginScreen() {
    const [email, setEmail] = useState('');
    const [password, setPassword] = useState('');
    const navigation = useNavigation();

    const handleLogin = async () => {
        try {
            const session = await account.createSession(email, password);
            Alert.alert('Success', 'Logged in successfully!');
            navigation.navigate('Home');
        } catch (error) {
            Alert.alert('Error', error.message);
        }
    };

    return (
        <View style={{ padding: 20 }}>
            <Text>Email</Text>
            <TextInput
                style={{ borderBottomWidth: 1, marginBottom: 20 }}
                value={email}
                onChangeText={setEmail}
                placeholder="Enter your email"
                keyboardType="email-address"
            />
            <Text>Password</Text>
            <TextInput
                style={{ borderBottomWidth: 1, marginBottom: 20 }}
                value={password}
                onChangeText={setPassword}
                placeholder="Enter your password"
                secureTextEntry
            />
            <Button title="Login" onPress={handleLogin} />
        </View>
    );
}
TL;DR
Developers are encountering an error with the `userId` param being too long. The solution lies in adjusting the `userId` parameter to contain a maximum of 36 characters, including only specific valid characters. The documentation for Appwrite offers guidance on resolving this issue.
YmajineUnBan !
19 Aug, 2024, 21:05

and the second part

YmajineUnBan !
19 Aug, 2024, 21:06

AppWrite.js

TypeScript
// appwriteClient.js
import { Client, Account } from 'appwrite';

const client = new Client()
  .setEndpoint('https://cloud.appwrite.io/v1') // Remplacez par l'URL de votre serveur Appwrite
  .setProject('66c3715f001bd1e503fb'); // Remplacez par votre ID de projet

const account = new Account(client);

export { account };
YmajineUnBan !
19 Aug, 2024, 21:06

help plz

Kenny
19 Aug, 2024, 21:19

The best help I can offer you, is to read the documentation for whatever tool you want to use.

Kenny
19 Aug, 2024, 21:21

If you look at the Appwrite documentation you can see you're using the wrong method for what you're trying to accomplish.

https://appwrite.io/docs/references/cloud/client-web/account#createSession

The documentation is pretty good, I would start there and if you have any more struggles let me know. But I think the best way for you to learn and grow is to understand the tool first.

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