-
Notifications
You must be signed in to change notification settings - Fork 2
feat: Add Better Auth #107
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
Open
JacksonMeade
wants to merge
18
commits into
main
Choose a base branch
from
new-authentication-provider
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Deploying wxyc-dj with
|
| Latest commit: |
a4c78d0
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://2b15eea2.dj-site.pages.dev |
| Branch Preview URL: | https://new-authentication-provider.dj-site.pages.dev |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Replace AWS Cognito with Better-Auth
Overview
This PR replaces AWS Cognito authentication with Better-Auth, a self-hosted authentication solution. The migration removes all AWS SDK dependencies and Cognito-specific code, replacing them with Better-Auth's client and server APIs.
Major Changes
Authentication Infrastructure
@aws-sdk/client-cognito-identity-providerdependencies and Cognito-specific authentication flows have been removedbetter-authpackage (v1.4.9) with plugins for admin, username, JWT, and organization supportmiddleware.ts) has been removed. Authentication checks are now handled at the component/route level using Better-Auth session utilitiesAPI Routes Removed
The following authentication-related API routes have been removed:
app/api/authentication/route.ts- Cognito authentication endpoints (GET/POST/PATCH)app/api/authentication/password/route.ts- Password management endpointsapp/api/authentication/utilities.ts- Cognito utility functionsapp/api/admin/djs/route.ts- DJ registry API (user profiles now managed via Better-Auth)app/api/admin/password/route.ts- Admin password managementNew Authentication Clients
lib/features/authentication/client.ts): React hooks-based client for use in client componentslib/features/authentication/server-client.ts): Server-only client for use in server components, middleware, and API routeslib/features/authentication/server-utils.ts): Helper functions for session management, role checking, and user data extractionSession Management
lib/features/session.ts): Replaced Cognito session management with Better-Auth session retrieval using cookie-based authenticationbetterAuthSessionToAuthenticationData()to convert Better-Auth sessions to the existingAuthenticationDataformat for backward compatibilityType System Updates
lib/features/authentication/types.ts):DJwtPayload)BetterAuthJwtPayload)WXYCRoletype for role managementrealNameanddjNameoptional fieldsBetterAuthSession,BetterAuthSessionResponse)AuthenticationSessiontype (refresh tokens handled by Better-Auth)Hooks Refactoring
Authentication hooks (
src/hooks/authenticationHooks.ts):useLogin()now usesauthClient.signIn.username()useLogout()usesauthClient.signOut()useAuthentication()usesauthClient.useSession()hookuseNewUser()usesauthClient.signUp.username()useResetPassword()updated to use Better-Auth admin APIAdmin hooks (
src/hooks/adminHooks.ts):useAccountListResults()now usesauthClient.admin.listUsers()AccounttypeDJ hooks (
src/hooks/djHooks.ts): Updated to work with Better-Auth user IDs (strings instead of numbers)Admin Features
lib/features/admin/better-auth-client.ts): Server-side admin client with access verificationlib/features/admin/conversions-better-auth.ts): Conversion utilities for Better-Auth user objectslib/features/admin/client.ts): Cognito-based admin client removedComponent Updates
src/components/experiences/modern/Leftbar/LeftbarLogout.tsx): Simplified to use Better-Auth sign-outConfiguration
Package.json:
better-authdependencyjoseandjwt-decodefor JWT handlingwebcrypt-sessionfor session managementEnvironment variables: Better-Auth base URL configured via
NEXT_PUBLIC_BETTER_AUTH_URL(defaults tohttp://localhost:8082/api/auth)Migration Notes
member,dj,musicDirector,stationManager/tokenendpoint instead of Cognito tokens