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
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.
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.
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
Updated UserMenu component:
Refactored UserMenu component to use the AuthProvider context, displaying the authenticated user’s principal.
Wrapped Root layout with AuthProvider:
Integrated the AuthProvider within the root layout file, ensuring that all pages and components can access the principal state.
Overview This pull request introduces a new authentication feature, including a custom hook -
useICPAuth
for handling authentication with Internet Identity, a globalAuthProvider
context to share the authenticated user's principal across the app, and component updates to integrate this new functionality.Changes Implemented
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.Added
AuthProvider
Context: Created anAuthProvider
context to store the user’s principal and provide it globally across the application. TheAuthProvider
makes it easy to access the authenticated user's principal in any component without prop drilling or relying on the hook.Updated
NavBar
component: RefactoredNavBar
component to use theuseICPAuth
hook to manage login/logout functionality andAuthProvider
context to obtain principal for managing conditional rendering for different statesUpdated
UserMenu
component: RefactoredUserMenu
component to use the AuthProvider context, displaying the authenticated user’s principal.Wrapped Root
layout
withAuthProvider
: Integrated theAuthProvider
within the root layout file, ensuring that all pages and components can access the principal state.Added
constants.ts
to centralize constant values