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
- I can't UNPAUSE my project with the free...
I received an email notifying me that my project had been paused due to inactivity, and the email included a link to "Restore project." However, that button red...
- How to bypass the rate limit on the back...
Once a month my app has a ton of usage and I always run into the Too many requests 429 error. I am trying to optimize the queues and jobs to manage that, but a...
- 401 - Project not accessible in this reg...
Hi Appwrite team, I’m experiencing a Cloud Console issue with my NYC region project. Problem: - Some Console pages return: “401 - Project is not accessible ...