Rank 2: Process
yeah accounts api for the client side access and users for server side with an API key
Votes
0
Replies
24
Participants
Unknown
Messages
25
Rank 2: Process
yeah accounts api for the client side access and users for server side with an API key
Rank 2: Process
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
Admin
Function call: ID.unique()
Rank 2: Process
where is that function defined? what should I import from the appwrite node sdk?
Rank 2: Process
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()'
Admin
Yes it's in the Appwrite node SDK. It's imported the same way you import Client
Rank 2: Process
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 😄 
Rank 2: Process
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
Rank 2: Process
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?
Rank 2: Process
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 🙂
Rank 2: Process
getting a connect ECONNREFUSED 127.0.0.1:4443 error for some reason with the function
Rank 2: Process
tried using http endpoint instead of https, same error
Rank 2: Process
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..
Rank 2: Process
welp guess that's a new question lol
Rank 2: Process
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; }};Rank 2: Process
I suppose it works, but got more things to figure out. can just mark this resolved
Rank 2: Process
[SOLVED] Enforce ID.unique() for all user accounts created