Back

role based login:

  • 0
  • Web
Manzar
26 Aug, 2024, 14:12

I want to redirect admin to admin page and others to user page, how can I do so?

TL;DR
Solution: To redirect admins to the admin page and others to the user page based on their labels, you can modify the code as follows: ```ts try { const account = account.get(); if (account.labels.includes('admin')) { redirect('admin'); } else { redirect('dashboard'); } } catch (err) { redirect('sign-in'); } ```
Kenny
26 Aug, 2024, 14:18

After the user is authenticated you can check it's labels to see if they're an admin and if they are redirect them to whatever page you want.

Kenny
26 Aug, 2024, 14:20

you can do something like

TypeScript
// This is just something I created quickly so it probably won't work as is lol

try {
  const account =  account.get();

  if(account.labels.includes('admin')) {
    redirect('admin');
  } else {
    redirect('dashboard');
  }
} catch (err) {
  redirect('sign-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