Add complete user authentication with NextAuth.js supporting: - Email/password credentials authentication - OAuth providers (GitHub, Google) with optional configuration - JWT-based session management with 30-day expiry - Role-based access control (USER, GROWER, FARM_MANAGER, ADMIN) - Permission system with granular access control - Secure password hashing with bcrypt (12 rounds) - Rate limiting on auth endpoints - Password reset flow with secure tokens - Email verification system Files added: - lib/auth/: Core auth library (types, permissions, context, hooks, middleware) - pages/api/auth/: Auth API routes (NextAuth, register, forgot-password, verify-email) - pages/auth/: Auth pages (signin, signup, forgot-password, reset-password, verify-email) - components/auth/: Reusable auth components (LoginForm, RegisterForm, AuthGuard, etc.) Updated _app.tsx to include SessionProvider for auth state management.
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import * as React from "react"
|
|
import Router from "next/router"
|
|
import { QueryClient, QueryClientProvider, Hydrate } from "@tanstack/react-query"
|
|
import { SessionProvider } from "next-auth/react"
|
|
import NProgress from "nprogress"
|
|
import { syncDrupalPreviewRoutes } from "next-drupal"
|
|
import "nprogress/nprogress.css"
|
|
|
|
import "styles/globals.css"
|
|
|
|
NProgress.configure({ showSpinner: false })
|
|
|
|
Router.events.on("routeChangeStart", function (path) {
|
|
syncDrupalPreviewRoutes(path)
|
|
NProgress.start()
|
|
})
|
|
Router.events.on("routeChangeComplete", () => NProgress.done())
|
|
Router.events.on("routeChangeError", () => NProgress.done())
|
|
|
|
export default function App({ Component, pageProps: { session, ...pageProps } }) {
|
|
const queryClientRef = React.useRef<QueryClient>()
|
|
if (!queryClientRef.current) {
|
|
queryClientRef.current = new QueryClient()
|
|
}
|
|
return (
|
|
<SessionProvider session={session}>
|
|
<QueryClientProvider client={queryClientRef.current}>
|
|
<Hydrate state={pageProps.dehydratedState}>
|
|
<Component {...pageProps} />
|
|
</Hydrate>
|
|
</QueryClientProvider>
|
|
</SessionProvider>
|
|
)
|
|
}
|