const token = jwt.sign( userId: user.id, role: user.role , process.env.JWT_SECRET, expiresIn: '7d' );
if (res.ok) window.location.href = '/dashboard'; else 'Login failed'); wepik.com login
const isValid = await bcrypt.compare(password, user.passwordHash); if (!isValid) return res.status(401).json( message: 'Invalid credentials' ); const token = jwt
const res = await fetch('/api/auth/login', method: 'POST', headers: 'Content-Type': 'application/json' , body: JSON.stringify( email, password ) ); const token = jwt.sign( userId: user.id
app.post('/api/auth/login', async (req, res) => const email, password = req.body; const user = await User.findOne( email ); if (!user) return res.status(401).json( message: 'Invalid credentials' );
const handleSubmit = async (e: React.FormEvent) => e.preventDefault(); setError('');
res.cookie('token', token, httpOnly: true, secure: process.env.NODE_ENV === 'production', sameSite: 'strict', maxAge: 7 * 24 * 60 * 60 * 1000 );