I want to save the preferences of my users during the signup phase, like this:
email: 'user@example.com',
password: 'password',
data: {'userType': 'doctor'}, // other is patient
);
but account.create does not have the data property. I have two different users, how can I separate them when signing up or?
Hi @Hz.Bootlegger ,
you can handle such situation like this:
await account.create(
email: 'user@example.com',
password: 'password',
).then((response) async {
//! TODO: you will need to login the user.
//! before running `updatePrefs`.
await account.updatePrefs(
prefs: {'userType': 'doctor'},
);
return response;
}).then((response) {
/// do whatever you want todo with `response` returned from `account.create` here
});
that's how you can handle it on client side.
or you can create function using Server SDK that can handles user creation process including updating prefs for that user. and you can call that function using function URL on client side to create user instead of using account.create from Appwrite SDK.
do you mean I'd open a session in between codebase but dont lead user to homepage as really logged in then update their pref and log out?
like fake session
yeah you can do it that way if you don't want to use function or server sdk, but I think that's not good way to approch it, you should use function approch instead.
server function replaces all account.create stuff ?
yes
you just need to send http POST request
to function URL
so its actually a rest
and function can handle the account.create & account.updatePrefs
functions can be executed via URLs as REST API.
okay I like it. Would you share the example link
you can get started with functions here: https://appwrite.io/docs/products/functions/quick-start
in this case the function I needed should be available for anyone but guests right?
or any is enough
guests is correct
for creating new user using server SDK in your function, refer this: https://appwrite.io/docs/references/cloud/server-nodejs/users#create
and for updating user's prefs using server SDK in function, refer this: https://appwrite.io/docs/references/cloud/server-nodejs/account#updatePrefs
Recommended threads
- Auto Updating Backend & Auth via Appwrit...
<@870607367597850624> Hey everyone 👋 I wanted to ask to ask for a friend, he’s asking if Appwrite be used in a similar way to Supabase when integrated with AI ...
- Is Database Operators available in Cloud...
Is it possible to do the above?
- How to use appwrite types
I am using appwrite types --language ts ./types to generate the types yielding something like: ``` import type { Models } from 'node-appwrite'; // This file i...