Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: admin authentication #3

Closed
wants to merge 14 commits into from
Closed

Conversation

Thechi2000
Copy link
Contributor

@Thechi2000 Thechi2000 commented Jun 29, 2024

Allows admin authentication through the usage of an admin token. To simplify session management (and the rest of the project), migrates to use the App router, in a src directory.

Adds:

  • A stub admin dashboard on /admin
  • A login page on /login?type=admin. Can be later reused as /login?type=tequila for the users.
  • Session management using JWTs in session.ts.
  • Two functions for URL management: getUrl() and buildUrl().
    In order to access the full url anywhere in the project (on server-side), I added a middleware which includes the url in a next-url header. This header will only be present on the server, and can be accessed using the getUrl() function, which wraps around the native headers().

Session tokens are managed in session.ts, which contains server actions. Those are server-side functions that can be directly called from the frontend (which is so neat, I love it). It (un)sets a cookie named admin-session, containing a JWT payload (see https://jwt.io/introduction).

The layout in src/app/admin ensures that a user has a valid session before accessing any page beneath. If there is not, then the user is redirected to /login?type=admin, where they will have to enter the admin token.

All UIs are stub, meant to be improved.

@Thechi2000 Thechi2000 added the enhancement New feature or request label Jun 29, 2024
@Thechi2000 Thechi2000 linked an issue Jun 29, 2024 that may be closed by this pull request
3 tasks
@Thechi2000 Thechi2000 mentioned this pull request Jun 29, 2024
3 tasks
@Thechi2000 Thechi2000 changed the title 2 authentication admin feat: admin authentication Jun 29, 2024
@Thechi2000 Thechi2000 force-pushed the 2-authentication-admin branch from 0a30741 to a040981 Compare June 29, 2024 20:14
@Thechi2000 Thechi2000 marked this pull request as ready for review June 30, 2024 07:51
@Thechi2000 Thechi2000 self-assigned this Jun 30, 2024
@Thechi2000 Thechi2000 closed this Aug 3, 2024
@Thechi2000 Thechi2000 deleted the 2-authentication-admin branch August 3, 2024 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Authentication flows
1 participant