Back

How to automatically add new user to a team?

  • 0
  • Teams
  • Web
  • General
  • Accounts
  • Users
kathelia.dokgu
30 Jul, 2023, 20:42

I'm confused -- what does this have to do with what we are discussing? res.status is a NextJS thing and is not related to appwrite.

TL;DR
User is seeking assistance with automatically adding a new user to a team. They have concerns about security and preventing unverified accounts from accessing the app. They are considering using custom permissions and have questions about how to implement them. They also mention confusion about server-side and client-side validation. A possible solution suggested is to use the `users/verified` role when setting permissions for collections.
Drake
30 Jul, 2023, 20:43

How are you blocking people?

Drake
30 Jul, 2023, 20:43

Oh sorry I thought this was an Appwrite function

Drake
30 Jul, 2023, 20:45

Are you sure this code is executing at all?

Drake
30 Jul, 2023, 20:45

My point is why create a team when there's something out of the box for you already?

kathelia.dokgu
30 Jul, 2023, 20:46

So I would basically call account.createEmailSession and then account.get() - which then gives me an account object that has a boolean emailVerification which would be true if they've verified their account. At least I believe so - that's my plan, I haven't coded that in yet.

Drake
30 Jul, 2023, 20:46

This is like doing client side validation only which is not secure

kathelia.dokgu
30 Jul, 2023, 20:48

Yes I can register just fine. The user is created, then the account.createMembership() gets called, then I have a createVerification() call after that which does get called.

Drake
30 Jul, 2023, 20:48

You sure an error isn't being thrown?

kathelia.dokgu
30 Jul, 2023, 20:49

I mean - I was trying to do SSR before but you suggested that I do CSR instead that's why I've been moving most of my logic on the client side.

kathelia.dokgu
30 Jul, 2023, 20:49

I do have a console.log in there but it's not showing anything.

Drake
30 Jul, 2023, 20:52

It doesn't matter if you do SSR because a bad actor can make API calls directly to Appwrite. Server side validation means putting the restrictions in Appwrite

kathelia.dokgu
30 Jul, 2023, 20:56

Which is why I am creating a bunch of teams to manage permissions, I'm putting the rules from inside appwrite. But in terms of checking if the user is verified, what else can I do? Didn't you say it was complicated to start a session on the NextJS backend and that I should just do it from the frontend? So I'm calling account.get() from the client side.

kathelia.dokgu
30 Jul, 2023, 20:59

Out of curiosity - what's out of the box? I have 2 needs:

  1. Prevent unverified accounts from logging into my app to force users to verify their email before they can use the app
  2. Protect one collection so that even though everyone who is logged in can create new documents under that collection, only users belonging to certain teams can actually read from it

What's the out of the box solution for the second item?

Drake
30 Jul, 2023, 21:06

But why create a team for everyone instead of using users or users/verified??

kathelia.dokgu
30 Jul, 2023, 21:16

Because I didn't want to use All users when setting permissions for the collection since that could potentially include accounts that are unverified. Ideally I would like to automatically assign users to the basic team right after the email verification is done instead of after their account was created.

Drake
30 Jul, 2023, 21:16

That's why I suggested users/verified.....

kathelia.dokgu
30 Jul, 2023, 21:17

Where can I find an example of this?

Drake
30 Jul, 2023, 21:19

In the console, select custom and then put the role string: https://appwrite.io/docs/rest#permissions

kathelia.dokgu
30 Jul, 2023, 21:39

It looks like you've dealt with my concerns before: https://github.com/appwrite/appwrite/discussions/5036

And looking at the solution as you've described - selecting custom and setting users/verified seems to work for others. Okay I can try that too - just gotta make sure to do it for all of my collections. This should take care of the second item on my list:

  1. Prevent unverified accounts from logging into my app to force users to verify their email before they can use the app
  2. Protect one collection so that even though everyone who is logged in can create new documents under that collection, only users belonging to certain teams can actually read from it

I'm still worried about the first item though - as you said, checking for emailVerification is not secure because that's on the client side. Bad actors can still potentially bypass this security check and get past the login screen but since the collections are protected, they should only see an empty shell of the app without any data. I get this - but I'm just not a fan of it. Ideally I don't even want them to see an empty shell of the app, just be stuck on the login screen.

kathelia.dokgu
30 Jul, 2023, 21:43

Is it normal for it to say "Not found"?

Drake
30 Jul, 2023, 22:24

No 🧐

kathelia.dokgu
30 Jul, 2023, 22:55

You mean "No, our team should change what that says" or "No, you messed up and it should show something else"? πŸ˜…

Drake
30 Jul, 2023, 23:00

Maybe you can create an issue? I've never seen that before and I can't test that right now on my phone

kathelia.dokgu
30 Jul, 2023, 23:10

Okay I submitted an issue.

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