Performance: NextAuth.js (Auth.js) setup
MEDIUM IMPACT
This affects page load speed and interaction responsiveness by adding authentication logic and network requests during initial page load and user actions.
import CredentialsProvider from 'next-auth/providers/credentials'; import NextAuth from 'next-auth'; export default NextAuth({ providers: [ CredentialsProvider({ authorize: async (credentials) => { // lightweight async call const user = await fetchUserFromAPI(credentials); return user || null; } }) ], callbacks: { session: async ({ session, token }) => { // minimal processing session.user.role = token.role; return session; } }, pages: { signIn: '/auth/signin' } });
import CredentialsProvider from 'next-auth/providers/credentials'; import NextAuth from 'next-auth'; export default NextAuth({ providers: [ CredentialsProvider({ authorize: async (credentials) => { // heavy synchronous logic or blocking calls here const user = await verifyUser(credentials); return user || null; } }) ], callbacks: { session: async ({ session, token }) => { // synchronous heavy processing session.user.role = token.role; return session; } } });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Blocking heavy auth logic in authorize callback | Minimal | 0 | Low | [X] Bad |
| Lightweight async auth calls with minimal session processing | Minimal | 0 | Low | [OK] Good |