hi guys i got a small question: How do i make my users usernames unique i dont want to have a 2 or more users with same username, this is my code
import { fail } from '@sveltejs/kit';
import { Client, Databases, ID } from 'appwrite';
export const actions = {
register: async ({ request }) => {
const data = await request.formData();
const username = data.get('username');
const password = data.get('password');
const passwordRepeat = data.get('password-repeat');
if (!username) {
return fail(400, { message: 'Please enter a username' });
}
if (!password) {
return fail(400, { message: 'Please enter a password' });
}
if (password !== passwordRepeat) {
return fail(400, { message: 'Passwords do not match' });
}
try {
const client = new Client()
.setEndpoint('https://cloud.appwrite.io/v1')
.setProject('xxx'); //OVO JE PROJECT ID
const databases = new Databases(client);
//PRVO JE DATABASE ID A DRUGO JE DOCUMENT ID
databases.createDocument('xxxx', 'xxx', ID.unique(), {
username,
password
});
} catch (e) {
console.log(e);
}
}
};
i tried to do the same thing with ID.unique() i tried the username.unique(), but it looks like it doesnt work, thanks in advance
Recommended threads
- Realtime for files() works almost well, ...
I have been trying to make use of realtime, today (14.03.26) I have pulled all the latest versions of docker images, and sdk available. Whats working: - Conn...
- Function issue
Hi,idk whats wrong with my function but i made some changes to the env var and made sure they saved then i redeployed it,but then after it redeeployed it asked ...
- Function issue
Hi,idk whats wrong with my function but i made some changes to the env var and made sure they saved then i redeployed it,but then after it redeeployed it asked ...