Badgegate / website

https://badgegate.vercel.app
0 stars 1 forks source link

feat: Implement Internet Identity Authentication with Custom Hook and Context #7

Closed KishoreVB70 closed 3 hours ago

KishoreVB70 commented 9 hours ago

Overview This pull request introduces a new authentication feature, including a custom hook - useICPAuth for handling authentication with Internet Identity, a global AuthProvider context to share the authenticated user's principal across the app, and component updates to integrate this new functionality.

Changes Implemented

  1. Created useICPAuth Hook: Implemented a custom hook, useICPAuth, to manage the login and logout flow with Internet Identity. Includes logic for checking if the user is authenticated and retrieving the principal identity on login. Handles session persistence, ensuring that the user remains authenticated across page reloads.

  2. Added AuthProvider Context: Created an AuthProvider context to store the user’s principal and provide it globally across the application. The AuthProvider makes it easy to access the authenticated user's principal in any component without prop drilling or relying on the hook.

  3. Updated NavBar component: Refactored NavBar component to use the useICPAuth hook to manage login/logout functionality and AuthProvider context to obtain principal for managing conditional rendering for different states

  4. Updated UserMenu component: Refactored UserMenu component to use the AuthProvider context, displaying the authenticated user’s principal.

  5. Wrapped Root layout with AuthProvider: Integrated the AuthProvider within the root layout file, ensuring that all pages and components can access the principal state.

  6. Added constants.ts to centralize constant values

vercel[bot] commented 9 hours ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
badgegate ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 1, 2024 11:26am