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.
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.Recommended threads