How j-goyal/google-oauth-nextjs works
1. This is a Next.js App Router frontend, not a standalone backend. The repository is organized around route-based UI screens under src/app, with shared layout, guards, and feature components supporting auth-protected pages.
2. The primary routes suggest an authentication and admin portal:
- public/entry paths: /, /sign-in, /callback
- protected app paths: /dashboard, /sessions
- admin-only paths: /admin/users
- access control/error paths: /403 and not-found
3. The top-level UI shell lives in src/app/layout.tsx and src/app/globals.css. Shared chrome is split into reusable pieces like Header, Footer, ProfileDropdown, and GlobalLoader, indicating the app uses a consistent app frame with loading and user-state awareness.
4. Authentication is a first-class subsystem. ClientAuthProvider, AuthLayout, SignInButton, and ManageAuth.module.ts point to a login/session bootstrap flow. The presence of src/app/callback/page.tsx and types/auth/GoogleAuthRequest.ts suggests an OAuth-style sign-in callback, likely Google-based, with frontend handling of the redirect completion step.
5. Authorization is enforced in the client UI via guard components rather than only by route structure. RoleGuard, AdminOnly, and SuperAdminOnly indicate role-based access control, while 403 is the explicit access-denied destination. utils/roleUtils.ts and constants/userRoles.ts centralize role logic so multiple screens can share the same rules.
6. The app has a clear admin management subsystem under src/components/admin and src/app/admin/users. This includes:
- listing users (AdminGetAllUsersContent)
- changing roles (UserRoleDropdown)
- inspecting user sessions (UserSessionsModal)
This is the main operational/admin surface of the product.
7. Session visibility is a separate domain, not just part of login. src/app/sessions/page.tsx, constants/userSessions.ts, types/sessions/*, utils/sessionUtils.ts, and ManageMe.module.ts suggest the UI can fetch and render current or historical sessions for the signed-in user, and admins can inspect sessions per user.
8. Data access is centralized in a service layer rather than being scattered through components. src/services/ManageAuth.module.ts, ManageMe.module.ts, and ManageUsers.module.ts are the feature-specific API boundaries. These likely wrap calls to an external identity/user management backend through a shared HTTP client.
9. The HTTP layer is abstracted in src/lib/axios.ts and src/lib/AxiosMethods.ts. This is the core integration point between the frontend and the backend API, and it likely handles request configuration, interceptors, and method helpers consistently across auth, user, and session endpoints.
10. State management is split into small global stores:
- useAuthStore for authenticated user/session state
- useGlobalLoader for app-wide loading state
This implies the UI reacts to auth transitions and network activity globally, not just within individual pages.
11. Shared UI primitives live in src/components/ui and appear to be a local design system layer. Components such as button, input, select, table, pagination, and data-table are reused by higher-level features. components.json suggests these primitives may be generated or styled via a component system like shadcn/ui.
12. Loading and skeleton states are intentionally separated from the main content. GlobalLoader handles app-level waiting states, while src/components/shimmer/* contains page-specific skeletons for the dashboard, header, access-denied view, and grid layouts. This indicates asynchronous data fetching is expected across multiple screens.
13. Error handling is normalized through utilities like getErrorMessage and isGloballyHandledError. That suggests the service layer and UI share a common pattern for translating API failures into user-facing messages, with some errors suppressed from duplicate handling.
14. Types and constants are split into domain-focused folders (types/auth, types/users, types/sessions, constants/*). This keeps user, auth, and session data contracts explicit and helps the architecture stay aligned with the backend API shape.
15. At a high level, the data flow is: route page mounts -> auth/client provider establishes current user -> guards decide access -> feature page calls a service module -> service uses the axios layer -> response populates stores/components -> UI renders tables, dropdowns, modals, or redirects to sign-in/403 as needed. The architecture is a client-heavy, role-aware admin portal with clear separation between routing, authorization, service access, and shared presentation.
Main entry points: ManageMe.module.ts Me Service · RoleGuard.tsx Role Guard · layout.tsx App Shell · axios.ts HTTP Client
Components 34
App Router
Route-based screens and the root shell.
- Home · Landing entry route at /.
src/app/page.tsx - App Shell · Root app layout and global styles.
src/app/layout.tsx - Dashboard · Authenticated dashboard page.
src/app/dashboard/page.tsx - Sessions · Signed-in user session view.
src/app/sessions/page.tsx - Sign In · Public sign-in page.
src/app/sign-in/page.tsx - Callback · Redirect completion for authentication.
src/app/callback/page.tsx - Admin Users · Admin-only user management page.
src/app/admin/users/page.tsx - Forbidden · Access-denied screen.
src/app/403/page.tsx - Not Found · Next.js not-found boundary.
src/app/not-found.tsx
Auth & Access
Login bootstrap, providers, and guards.
- Auth Provider · Bootstraps authenticated client state.
src/components/ClientAuthProvider.tsx - Auth Layout · Wraps auth-sensitive UI and routing.
src/components/AuthLayout.tsx - Sign In Button · Starts the sign-in flow.
src/components/SignInButton.tsx - Role Guard · Shared role-based route guard.
src/components/RoleGuard.tsx - Admin Only · Restricts content to admins.
src/components/AdminOnly.tsx - Super Admin Only · Restricts content to super admins.
src/components/SuperAdminOnly.tsx
Admin Surface
User management and admin session inspection.
- User List · Admin user listing and actions.
src/components/admin/AdminGetAllUsersContent.tsx - Role Picker · Changes a user's role.
src/components/admin/UserRoleDropdown.tsx - Sessions Modal · Shows sessions for a selected user.
src/components/admin/UserSessionsModal.tsx
Data Layer
HTTP client, feature services, stores, and domain contracts.
- Auth Store · Authenticated user and session state.
src/store/useAuthStore.ts - HTTP Client · Shared request client and method helpers.
src/lib/axios.ts - Method Helpers · Reusable HTTP method wrappers.
src/lib/AxiosMethods.ts - Auth Service · Auth and callback-related API boundary.
src/services/ManageAuth.module.ts - Me Service · Current-user and session API boundary.
src/services/ManageMe.module.ts - Users Service · Admin user-management API boundary.
src/services/ManageUsers.module.ts - Session Utils · Transforms and formats session data.
src/utils/sessionUtils.ts - Role Utils · Centralized role checks and mapping.
src/utils/roleUtils.ts - Error Utils · Normalizes and suppresses handled errors.
src/utils/getErrorMessage.ts - Handled Error Check · Marks errors already handled globally.
src/utils/isGloballyHandledError.ts - User Roles · Role names and access tiers.
src/constants/userRoles.ts - Session Constants · Session-related labels and settings.
src/constants/userSessions.ts
Shared UI
Reusable chrome, primitives, loaders, and shimmers.
- Global Loader · App-wide loading state coordination.
src/components/GlobalLoader.tsx - Header · Top-level app navigation and status area.
src/components/Header.tsx - Footer · Bottom app chrome.
src/components/Footer.tsx - Profile Menu · Signed-in user actions and account menu.
src/components/ProfileDropdown.tsx
Connections 36
- App Shell → Auth Provider: wraps · Root shell initializes client auth state.
- App Shell → Header: uses · Shared app chrome rendered in the shell.
- App Shell → Footer: uses · Shared app chrome rendered in the shell.
- App Shell → Global Loader: coordinates · Global loading feedback is mounted at the top level.
- Home → Auth Layout: enters · Landing route is mediated by auth-aware layout.
- Sign In → Sign In Button: renders · Public entry point exposes sign-in action.
- Callback → Auth Service: completes via · OAuth callback flow hands off to auth service.
- Dashboard → Role Guard: protected by · Dashboard requires authenticated access.
- Sessions → Role Guard: protected by · Session page requires authenticated access.
- Admin Users → Admin Only: protected by · Admin user page is admin-restricted.
- Admin Users → Super Admin Only: protected by · Some actions require super-admin access.
- Forbidden → Role Guard: targeted by · Guard failures redirect here.
- Auth Provider → Auth Store: hydrates · Authenticated state is stored globally.
- Auth Layout → Auth Store: reads · Layout adapts to current auth state.
- Role Guard → Role Utils: checks · Shared role logic powers guards.
- Role Guard → User Roles: compares · Role constants define the access tiers.
- Admin Only → Role Utils: checks · Admin gating uses shared role logic.
- Super Admin Only → Role Utils: checks · Super-admin gating uses shared role logic.
- Header → Profile Menu: includes · User menu lives in the header.
- User List → Role Picker: uses · Admin table includes role-changing control.
- User List → Sessions Modal: opens · Admin table can inspect a user's sessions.
- User List → Users Service: loads via · Admin list is populated from the users service.
- Sessions Modal → Me Service: loads via · Session details are fetched from the me/session service.
- Sessions → Me Service: loads via · Signed-in user session page fetches session data.
- Auth Service → HTTP Client: uses · Feature service calls share the HTTP client.
- Me Service → HTTP Client: uses · Feature service calls share the HTTP client.
- Users Service → HTTP Client: uses · Feature service calls share the HTTP client.
- HTTP Client → Method Helpers: delegates to · Method wrappers sit beneath the client config.
- Me Service → Session Utils: formats · Session payloads are normalized for UI use.
- Me Service → Session Constants: uses · Session module shares constants and labels.
- Users Service → Error Utils: handles · Service errors are normalized for display.
- Auth Service → Error Utils: handles · Auth errors are normalized for display.
- Error Utils → Handled Error Check: filters · Global error suppression avoids duplicate handling.
- Dashboard → Global Loader: shows · Dashboard can surface loading state.
- Sessions → Global Loader: shows · Session page can surface loading state.
- Admin Users → Global Loader: shows · Admin page can surface loading state.