
yeah accounts api for the client side access and users for server side with an API key

im on 1.3.1 appwrite version, maybe the 1.3.2 version uses 'ID.unique()'
?

not a 100% sure. I'm away from my laptop so can't check immediately

Function call: ID.unique()

where is that function defined? what should I import from the appwrite node sdk?

i would think that would have to happen on server side to ensure it is unique/valid or a collision would result in an error unless the function just returns the string 'unique()'

Yes it's in the Appwrite node SDK. It's imported the same way you import Client

Ah, thanks, found it
class ID {
static custom(id) {
return id;
}
static unique() {
return 'unique()';
}
}
guess I missed it with my client wrapper

heyo, is your issue resolved? if it hasn't feel free to ask any more questions, but if it has, let me know so I can mark it as solved 😄 <:appwritepeepo:902865250427215882>

well i started on creating a function to do this but now im getting this from the cli
✗ Error Command failed: git clone --depth 1 --sparse https://github.com/appwrite/functions-starter .
Cloning into '.'...
fatal: cannot change to 'https://github.com/appwrite/functions-starter': No such file or directory
error: failed to initialize sparse-checkout

Have a look at this: https://discord.com/channels/564160730845151244/1089995079088869396

It was the same issue, and updating git fixed it

also make sure your appwrite CLI is up to date

yup just updated git and worked too, thanks for the help! saved a lot of time there my next challenge is to see if I can get typescript'd functions

In that case, I'll mark the issue as solved?

well i guess I will try to get the user creation function working and share it here for others

alright, that's better

if you need any help, let me know 🙂

getting a connect ECONNREFUSED 127.0.0.1:4443
error for some reason with the function

tried using http endpoint instead of https, same error

hmm using my host ip from my local network worked, that's not cool, my local network ip isn't static and I don't think my router even allows that..

welp guess that's a new question lol

module.exports = async function (req, res) {
const client = new sdk.Client();
const users = new sdk.Users(client);
if (
!req.variables['APPWRITE_FUNCTION_ENDPOINT'] ||
!req.variables['APPWRITE_FUNCTION_API_KEY'] ||
!req.variables['APPWRITE_FUNCTION_PROJECT_ID']
) {
console.error("Environment variables are not set. Function cannot use Appwrite SDK.");
res.json({
success: false,
error: "Server Error",
}, 500);
return;
} else {
client
.setEndpoint(req.variables['APPWRITE_FUNCTION_ENDPOINT'])
.setProject(req.variables['APPWRITE_FUNCTION_PROJECT_ID'])
.setKey(req.variables['APPWRITE_FUNCTION_API_KEY'])
.setSelfSigned(true);
}
if (!req.payload) {
console.error("Invalid request");
res.json({
success: false,
error: "Invalid request",
}, 400);
return;
}
const data = JSON.parse(req.payload);
/* Additional validaiton omitted */
if (!isValidPassword(data.password)) {
console.error("Invalid password");
res.json({
success: false,
error: "Invalid password",
}, 400);
return;
}
try {
const user = await users.create(sdk.ID.unique(), data.email, undefined, data.password);
res.json({
success: true,
data: {
userId: user.$id,
username: data.username,
},
});
} catch (error) {
res.json({
success: false,
error: error.message,
}, error?.code || 400);
return;
}
};

I suppose it works, but got more things to figure out. can just mark this resolved

[SOLVED] Enforce ID.unique()
for all user accounts created
Recommended threads
- Upgrade Issue
Am having issue upgrading my appwrite account to pro as my card number is 19 and the required input is 16 digit
- createEmailPasswordSession Error using S...
Did someone succeed using SSR approach for login?
- [Solved] how to get user prefs from serv...
i want to get a specific users preferences from serverside maybe i missunderstood something
