Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save skolhustick/f077e78a19162b18867a096ea0d8e694 to your computer and use it in GitHub Desktop.
Save skolhustick/f077e78a19162b18867a096ea0d8e694 to your computer and use it in GitHub Desktop.
import React, { useState } from 'react'
import { signIn } from 'next-auth/react'
const Login = () => {
const [email, setEmail] = useState('')
const sendLoginVerification = e => {
e.preventDefault()
// Notice, we are also redirecting users to the protected route instead of the homepage after signing in.
signIn('email', { callbackUrl: '/protected', email })
}
return (
<div>
<h1>Login</h1>
<h3>
Enter your email address, and we will send you a verification link.
</h3>
<form onSubmit={sendLoginVerification}>
<input
type='email'
value={email}
required
onChange={e => setEmail(e.target.value)}
/>
<button type='submit'>Send Magic Link 🪄</button>
</form>
</div>
)
}
export default Login
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment