feat(auth): Implement Secure Authentication System with JWT and OAuth#20
Merged
feat(auth): Implement Secure Authentication System with JWT and OAuth#20
Conversation
…t variable access
…ken generation and verification
…le OAuth authentication
…get, and clear functions
…er info retrieval
…word, Google OAuth utilities, and constants
…forwardRef support
…e and user verification
…out functionality
…get, and clear functions
…neration, token exchange, and user info retrieval
…on and URL builders
…uth pages to admin dashboard
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 32 out of 37 changed files in this pull request and generated 7 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ing on auth pages
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
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.
Summary:
Implemented a robust authentication system for the admin dashboard, supporting both email/password login and Google OAuth. The system utilizes a dual-token strategy (Access + Refresh tokens) secured via HttpOnly cookies and implemented using the
joselibrary for edge compatibility. This foundational work enables secure access control for future admin features.Changes:
Implemented Authentication Logic (
src/lib/auth/):jwt.tsto sign and verify Access (15 min) and Refresh (7 days) tokens usingHS256.cookies.tsto handle secure, HttpOnly cookie storage and retrieval.session.tsto manage high-level auth flows (login, logout, refresh,getCurrentUser).google.tsto handle the Google OAuth 2.0 authorization code flow.bcryptjsinpassword.tsfor secure password hashing and verification.Created Auth API Routes (
src/app/api/auth/):POST /login: Validates credentials and sets auth cookies.POST /logout: Clears auth cookies.GET /me: Returns the currently authenticated user.GET /google&/google/callback: Handles the OAuth handshake and user verification.Built Login UI (
src/app/admin/login/page.tsx):Set up Admin Dashboard Skeleton (
src/app/admin/(authenticated)/):Configuration Updates:
JWT_SECRET,GOOGLE_CLIENT_ID, andGOOGLE_CLIENT_SECRETto environment validation (src/config/env.ts).prisma/seed.tsto hash the default admin password usingbcrypt.next.config.mjsimage domains.Dependencies:
josefor JWT operations,bcryptjsfor hashing, and@types/bcryptjs.@radix-ui/react-labelfor accessible form inputs.