Back

[SOLVED] Check auth & redirection in Next.js 13 App Router with appwrite

  • 0
  • Web
vishalxtyagi
27 Sep, 2023, 16:53

I do have one more doubt, this is my directory in my next.js 13 application and I'm using useEffect to check for auth and redirection but due to which if someone tries to access protected page, the content is visible for few seconds after that useEffect redirects if not authenticated, Instead I want to show loading state from loading.tsx file of protected route until it will check authentication

TL;DR
Solution: To ensure that the user cannot retrieve data they don't have access to, double-check the permissions configuration. For the loading state, set `loading = true` initially and don't show any content. After checking the authentication, set `loading = false` and then display the content. To implement a loading state from the `loading.tsx` file of the protected route, modify the `useEffect` function. Instead of immediately redirecting when not authenticated, display the loading state until the authentication check is complete.
Drake
27 Sep, 2023, 21:11

First, make sure you have permissions configured such that the user cannot retrieve data they don't have access to.

For the loading...you can start with loading = true and don't show any content. Then, after checking auth, set loading = false and then show the content.

vishalxtyagi
28 Sep, 2023, 00:57

Got it, Thanks for the help

Drake
29 Sep, 2023, 23:42

[SOLVED] Check auth & redirection in Next.js 13 App Router with appwrite

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