Back

Create user preferences at registering phase

  • 0
  • Databases
  • Flutter
Hz.Bootlegger
5 Feb, 2024, 11:24

I want to save the preferences of my users during the signup phase, like this:

TypeScript
  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?

TL;DR
Developers are discussing how to save user preferences during the signup phase. They suggest using the server SDK to create a function that handles the user creation process and updates preferences. The function can be called using a function URL on the client side. An example code snippet is provided for reference. There is no specific solution mentioned in the thread, but the developers provide guidance on implementing the desired functionality.
kamal.panara
5 Feb, 2024, 11:31

Hi @Hz.Bootlegger ,

you can handle such situation like this:

TypeScript
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
});
kamal.panara
5 Feb, 2024, 11:33

that's how you can handle it on client side.

kamal.panara
5 Feb, 2024, 11:35

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.

Hz.Bootlegger
5 Feb, 2024, 11:43

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?

Hz.Bootlegger
5 Feb, 2024, 11:43

like fake session

kamal.panara
5 Feb, 2024, 11:45

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.

Hz.Bootlegger
5 Feb, 2024, 11:45

server function replaces all account.create stuff ?

kamal.panara
5 Feb, 2024, 11:45

yes

kamal.panara
5 Feb, 2024, 11:46

you just need to send http POST request

kamal.panara
5 Feb, 2024, 11:46

to function URL

Hz.Bootlegger
5 Feb, 2024, 11:46

so its actually a rest

kamal.panara
5 Feb, 2024, 11:46

and function can handle the account.create & account.updatePrefs

kamal.panara
5 Feb, 2024, 11:47

functions can be executed via URLs as REST API.

Hz.Bootlegger
5 Feb, 2024, 11:47

okay I like it. Would you share the example link

kamal.panara
5 Feb, 2024, 11:48

you can get started with functions here: https://appwrite.io/docs/products/functions/quick-start

Hz.Bootlegger
5 Feb, 2024, 11:53

in this case the function I needed should be available for anyone but guests right?

Hz.Bootlegger
5 Feb, 2024, 11:54

or any is enough

kamal.panara
5 Feb, 2024, 11:54

guests is correct

kamal.panara
5 Feb, 2024, 11:55
kamal.panara
5 Feb, 2024, 11:58

for creating new user using server SDK in your function, refer this: https://appwrite.io/docs/references/cloud/server-nodejs/users#create

kamal.panara
5 Feb, 2024, 11:58

and for updating user's prefs using server SDK in function, refer this: https://appwrite.io/docs/references/cloud/server-nodejs/account#updatePrefs

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more