Skip to content

feat(auth): roles and admin dashboard protection#37

Merged
martin0024 merged 6 commits intodevfrom
feature/7-roles
Apr 4, 2026
Merged

feat(auth): roles and admin dashboard protection#37
martin0024 merged 6 commits intodevfrom
feature/7-roles

Conversation

@Jxl-s
Copy link
Copy Markdown

@Jxl-s Jxl-s commented Apr 1, 2026

Closes #7

Summary

  • Add userRoleEnum (admin, coach, user) and full profiles schema (first_name, last_name, role, avatar_url, stripe_customer_id, updated_at)
  • Collect first name and last name on signup, passed as user_metadata to Supabase
  • Middleware protects /dashboard/* — non-admins are redirected to /
  • Admin dashboard page shows email, role, and user ID

Supabase setup required

Two triggers must be added via SQL Editor (see issue comments):

  1. on_auth_user_created — creates a profiles row with name + default role on signup
  2. on_profile_role_updated — syncs profiles.roleapp_metadata.role in the JWT whenever role changes

Test plan

  • Sign up with first + last name → profile row created in Supabase with correct name and role = user
  • Log in as a regular user → visiting /dashboard redirects to /
  • Set a user's role to admin in Supabase → sign out and back in → /dashboard is accessible
  • Change profiles.roleapp_metadata updates automatically (verify in Supabase auth users table)

This comment was marked as resolved.

Copy link
Copy Markdown
Contributor

@martin0024 martin0024 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

other than that LGTM, good work guys, thanks!

@RenaudBernier RenaudBernier self-requested a review April 1, 2026 02:33
@Berny-ft Berny-ft closed this Apr 1, 2026
@Berny-ft Berny-ft reopened this Apr 1, 2026
Copy link
Copy Markdown

@RenaudBernier RenaudBernier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, do my requested edit if you have time

@achneerov achneerov linked an issue Apr 2, 2026 that may be closed by this pull request
6 tasks
redirect(
`/login?message=${encodeURIComponent("Check your email to confirm your account.")}`
);
redirect("/login?message=Check+your+email+to+confirm+your+account.");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make a enum file for strings like this? something like constants.js, and maybe we would put it in a constants folder maybe in lib/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, we don't have that much strings, let's try to not over complicate the project for nothing. Later on, if we do have a lot of strings we could yes. Usually having a lib for strings is useful when you have locales translation in multiple languages.

Comment on lines +48 to +49
? "Sign in to your account"
: "Fill in your details to get started"}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above, maybe in a constants file?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment. See previous

@martin0024 martin0024 merged commit 6d579ff into dev Apr 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Issue]: Auth Roles and Permissions

6 participants