-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(provider): allow disabling redirection on sign in with email (#1416
) * feat: allow to disable client-side redirect for email provider * docs(client): mention that redirect can also be disabled for email provider * feat: only display one email input in email page
- Loading branch information
1 parent
d86609a
commit 71c78e8
Showing
4 changed files
with
87 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import * as React from 'react' | ||
import { signIn, signOut, useSession } from 'next-auth/client' | ||
import Layout from 'components/layout' | ||
|
||
export default function Page () { | ||
const [response, setResponse] = React.useState(null) | ||
const [email, setEmail] = React.useState('') | ||
|
||
const handleChange = (event) => { | ||
setEmail(event.target.value) | ||
} | ||
|
||
const handleLogin = (options) => async (event) => { | ||
event.preventDefault() | ||
|
||
if (options.redirect) { | ||
return signIn('email', options) | ||
} | ||
const response = await signIn('email', options) | ||
setResponse(response) | ||
} | ||
|
||
const handleLogout = (options) => async (event) => { | ||
if (options.redirect) { | ||
return signOut(options) | ||
} | ||
const response = await signOut(options) | ||
setResponse(response) | ||
} | ||
|
||
const [session] = useSession() | ||
|
||
if (session) { | ||
return ( | ||
<Layout> | ||
<h1>Test different flows for Email logout</h1> | ||
<span className='spacing'>Default:</span> | ||
<button onClick={handleLogout({ redirect: true })}>Logout</button><br /> | ||
<span className='spacing'>No redirect:</span> | ||
<button onClick={handleLogout({ redirect: false })}>Logout</button><br /> | ||
<p>Response:</p> | ||
<pre style={{ background: '#eee', padding: 16 }}>{JSON.stringify(response, null, 2)}</pre> | ||
</Layout> | ||
) | ||
} | ||
|
||
return ( | ||
<Layout> | ||
<h1>Test different flows for Email login</h1> | ||
<label className='spacing'> | ||
Email address:{' '} | ||
<input type='text' id='email' name='email' value={email} onChange={handleChange} /> | ||
</label><br /> | ||
<form onSubmit={handleLogin({ redirect: true, email })}> | ||
<span className='spacing'>Default:</span> | ||
<button type='submit'>Sign in with Email</button> | ||
</form> | ||
<form onSubmit={handleLogin({ redirect: false, email })}> | ||
<span className='spacing'>No redirect:</span> | ||
<button type='submit'>Sign in with Email</button> | ||
</form> | ||
<p>Response:</p> | ||
<pre style={{ background: '#eee', padding: 16 }}>{JSON.stringify(response, null, 2)}</pre> | ||
</Layout> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71c78e8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: