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

add Authentication useing auth hook #2

Merged
merged 9 commits into from
Feb 6, 2025
Merged

Conversation

ahmad-kashkoush
Copy link
Collaborator

@ahmad-kashkoush ahmad-kashkoush commented Feb 4, 2025

Resolves #1

Summary of Changes

  1. Implemented NextAuth.js for authentication

    • Set up OAuth with Google.
    • Created app/api/auth/[...nextauth]/route.ts for handling authentication.
    • Configured SessionProvider for session management.
  2. Separated AuthProvider from RootLayout

    • Created components/AuthProvider.tsx to wrap SessionProvider.
    • Modified app/layout.tsx to include AuthProvider without breaking metadata.
  3. Redirected Users After Sign-In

    • Updated AuthButton.tsx to use signIn("google", { callbackUrl: "/me" }).
    • Ensured users are taken to /me after authentication.
  4. Protected the /me Page

    • Implemented client-side redirection in app/(protected)/me/page.tsx.
    • Redirects unauthenticated users to /login.
  5. Added Middleware for Route Protection (Optional Enhancement)

    • Created middleware.ts to enforce authentication for /me.
    • Unauthenticated users are redirected to /login.

Next Steps

  • Optional: Add role-based authentication (admin/user).
  • Consider integrating database storage for user sessions using Prisma. or whatever java does

@ahmad-kashkoush
Copy link
Collaborator Author

معلش علي الأرقام الخزعبليه ديه, عشان كدا لازم نظبط فورماتتر بدل ما الكلام دا يحصل تاني

@AmrMustafa282 AmrMustafa282 merged commit 2267edd into main Feb 6, 2025
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.

Implementing authentication for oAuth
2 participants