Back

Express-Appwrite-authentication example?

  • 0
  • Web
smilebasti
20 Mar, 2023, 16:56

Hi, is out there an example how to authenticate with appwrite with Node.js or Express.

I tried https://github.com/appwrite/playground-for-web, but this example does not have multisite authentication like the todo-demos for the other languages on GitHub.

Would be either great to have such a web-todo-demo or if anybody can share an example of how to authenticate with express?

Thanks ahead for any help πŸ™‚

TL;DR
The user is requesting an example of how to authenticate with Appwrite using Node.js and Express. Another user suggests that using Express may complicate things and recommends using the client SDK on the front-end instead. If the user still wants to use Express, they would need to manually handle the authentication process by sending the user's email and password to Appwrite, storing the session cookie in the Express app, and verifying the session on restricted pages. The user mentions wanting a multisite authentication similar to the Todo demos. Another user suggests not building on top of the Appwrite web playground as it doesn't follow best practices. The user then expresses their
Drake
20 Mar, 2023, 17:20

Honestly, I would not recommend using express because Appwrite is supposed to be your back-end server, and adding an extra layer in between makes things complicated.

The client SDK was designed to be used on the front ned, so you may not be able to use it in your express app. If you really want to use express and Appwrite's authentication mechanism, you'll have to manually make the API call to create a session and manually manage the session cookie returned from Appwrite.

smilebasti
20 Mar, 2023, 17:26

Ok Thanks.

smilebasti
20 Mar, 2023, 17:28

I just wanted to build on top of the web-playground example. Not sure how to build a web app that's multisite without express and has appwrite authentication.

Drake
20 Mar, 2023, 17:36

the web playground is just a sample to show how the SDK works. you definitely shouldn't build on top of it as it doesn't follow any sort of best practices for building an app.

Drake
20 Mar, 2023, 17:36

Not sure how to build a web app that's multisite

What do you mean by multisite?

smilebasti
21 Mar, 2023, 12:48

With multisite i mean something like the todo demos (with restricted and unrestricted sites) and without react or similar. I tried it with plain html, node and appwrite as backend but i am not sure how to handle the restricted sites

Drake
21 Mar, 2023, 15:55

Again, using express is much more complicated because you must manage the session yourself.

If you really want to, you'll have to handle login:

  1. accept the user's email and password
  2. manually send that to Appwrite (w/o the SDK)
  3. grab the session cookie from the response
  4. store that in a session in your express app

Then, when someone tries to access a restricted page your express app would need to:

  1. try to pull the appwrite session out of the express session
  2. make an account.get() API call to Appwrite to verify the session is valid
  3. send the user to the restricted page
  4. otherwise, send the user to the login page
Drake
21 Mar, 2023, 15:59

If you build a single-page app, you wouldn't need to do 2, 3, 4 from the login and 1 from the second part.

smilebasti
26 Mar, 2023, 08:01

Ok thanks for your answer πŸ™‚

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