Performance: Provider configuration (OAuth, credentials)
This affects page load speed and interaction responsiveness by controlling how authentication data is fetched and managed during server and client rendering.
import NextAuth from 'next-auth'; import GoogleProvider from 'next-auth/providers/google'; export default NextAuth({ providers: [ GoogleProvider({ clientId: process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID, clientSecret: process.env.GOOGLE_CLIENT_SECRET }) ], secret: process.env.NEXTAUTH_SECRET, session: { strategy: 'jwt' }, callbacks: { async jwt({ token, user }) { if (user) { token.id = user.id; } return token; } } });
import NextAuth from 'next-auth'; import Providers from 'next-auth/providers'; export default NextAuth({ providers: [ Providers.Google({ clientId: process.env.GOOGLE_CLIENT_ID, clientSecret: process.env.GOOGLE_CLIENT_SECRET }) ], callbacks: { async jwt(token, user) { if (user) { token.id = user.id; } return token; } }, session: { jwt: true } });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous env var access and no caching | Minimal | 0 | Blocks initial paint for 100-200ms | [X] Bad |
| Async provider config with caching and NEXT_PUBLIC vars | Minimal | 0 | Non-blocking, fast paint | [OK] Good |
providers[0].id?
import GoogleProvider from 'next-auth/providers/google';
const providers = [
GoogleProvider({ clientId: process.env.GOOGLE_ID, clientSecret: process.env.GOOGLE_SECRET })
];import CredentialsProvider from 'next-auth/providers/credentials';
export const authOptions = {
providers: [
CredentialsProvider({
name: 'Credentials',
credentials: {
username: { label: 'Username', type: 'text' },
password: { label: 'Password', type: 'password' }
},
authorize: async (credentials) => {
if (credentials.username === 'admin' && credentials.password === '1234') {
return { id: 1, name: 'Admin' };
}
return null;
}
})
]
};authOptions?Pass the test and this pattern moves unknown