bcgov / cas-registration

A web app for Registration in OBPS under the Clean Growth branch
Apache License 2.0
1 stars 1 forks source link

Bump next-auth.js to auth.js (version 5) #1507

Open shon-button opened 2 months ago

shon-button commented 2 months ago

Description of the Tech Debt

Our front-end authentication solution uses NextAuth.js version "^4.24.4" but, NextAuth.js version 5, now called Auth.js, is a major rewrite of the next-auth package. Auth.js aims to improve and streamline authentication using standard Web APIs and single method authentication setup while introducing as few breaking changes as possible. See migrating-to-v5

New Features

Migration Steps

Steps to create auth v5 JWT tokens for GitHub secrets

Note Not changing the .env vars to follow AUTH_ naming convention

There are no breaking changes to the environment variables, but some new best practices have been implemented for environment variables.
All environment variables should be prefixed with AUTH_, NEXTAUTH_ is no longer in use.
If you name your provider secret / clientId variables using this syntax, i.e. AUTH_GITHUB_SECRET and AUTH_GITHUB_ID, they will be auto-detected and you won’t have to explicitly pass them into your provider’s configuration.
The NEXTAUTH_URL/AUTH_URL is not strictly necessary anymore in most environments. We will auto-detect the host based on the request headers.
The AUTH_TRUST_HOST environment variable serves the same purpose as setting trustHost: true in your Auth.js configuration. This is necessary when running Auth.js behind a proxy. When set to true we will trust the X-Forwarded-Host and X-Forwarded-Proto headers passed to the app by the proxy to auto-detect the host URL (AUTH_URL)
The AUTH_SECRET environment variable is the only variable that is really necessary. You do not need to additionally pass this value into your config as the secret configuration option if you’ve set the environment variable.
  - NEXTAUTH_SECRET=AUTH_SECRET
  - KEYCLOAK_CLIENT_ID=AUTH_KEYCLOAK_CLIENT_ID
  - KEYCLOAK_CLIENT_SECRET=AUTH_KEYCLOAK_CLIENT_SECRET
  - KEYCLOAK_LOGIN_URL=AUTH_KEYCLOAK_ISSUER

Tech Debt Triage

Risk Value Scoring:

Level Value
High 3
Medium 2
Low 1
Technical Debt - Risk Types Level Value
Business Area Risk - Risk of business area visibility / damage to user experience
Developer Fault Risk - How likely will this tech debt cause a future error related to coding on top of it
System Fault Risk - Risk of system errors or application downtime
Time Scale Risk - Compound risk effect if left alone. How much more difficult to fix or dangerous will this become over time?
Time Sink Risk - How much will this tech debt slow the development process down
TOTAL SCORE:
shon-button commented 2 months ago

Session strategies https://authjs.dev/reference/nextjs/jwt https://authjs.dev/concepts/session-strategies https://authjs.dev/guides/creating-a-database-adapter#user-management