Click to log in: ${magicLink}
`, + }); + res.status(200).json({ message: 'Magic link sent' }); + } catch (error) { + res.status(500).json({ error: 'Failed to send email' }); + } +}; + +export const verifyMagicLink = (req: Request, res: Response) => { + const { token } = req.query; + + try { + const decoded = jwt.verify(token as string, process.env.JWT_SECRET as string) as { email: string }; + res.status(200).json({ message: 'Authenticated', email: decoded.email }); + } catch (err) { + res.status(401).json({ error: 'Invalid or expired token' }); + } +}; +``` +{message}
+