Skip to content
Back

Is my authentication process correct?

  • 0
  • Web
David
26 Oct, 2024, 09:57

I am using TypeScript, Appwrite, and Next.js to build an app. I want to authenticate and authorize users. I have two functions in ./lib/appwrite.ts These functions are login() and getCurrentUser().

In the login function I rely on account.createEmailPasswordSession and redirect to the appropriate protected route. In the appropriate protected route I invoke getCurrentUser() to get the logged in user then redirect to login route if the user is null or remain.

Unfortunately, the getCurrentUser() is always returning null and keeps redirecting back to the login route.

Here is my code for assistance.

https://dpaste.org/LR74G

TL;DR
Developers are having issues with authentication and authorization in their app using TypeScript, Appwrite, and Next.js. The getCurrentUser() function keeps returning null and redirecting back to the login route. The issue may be related to how the authentication process is handled. Ensure that the JWT token is properly set and sent in subsequent requests after logging in.
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