4. Credentials Provider and Password Verification
Implement safe credentials validation and understand exactly what the authorize function does and does not do.
What Credentials Provider Does
The Credentials provider lets you implement custom login logic. authorize(credentials, request) should return a minimal user object on success or null when credentials are rejected. It does not hash passwords, create a registration flow, rate-limit attempts, or automatically persist users.
Password Storage and Error Handling
Never store plaintext passwords or invent a hashing algorithm. Use a maintained password-hashing algorithm such as Argon2id or bcrypt in the trusted backend. Return generic errors for unknown accounts and wrong passwords to reduce account enumeration. Never log raw credentials.
Test Credentials Sign-In
Create a test account through your real backend and test both valid and invalid login attempts. A successful authorize return needs a stable id; returning null rejects login. Do not hard-code production credentials in source code.
The Credentials provider does not create user records or automatically persist credentials-authenticated users. Your identity backend owns that lifecycle.