Skip to content

Commit 5bc8f8b

Browse files
authored
docs(page): correct getCsrfToken and input types (#1651)
This fixes the a mismatch between the import (`csrfToken`) and the method (`getCsrfToken`) used in `getInitialProps`/`getServerSideProps`. In addition the form input fields now have their correct type: `email` for email input (for better autocomplete, virtual keyboard support and native validation) and `password` for the password input (to hide password while typing).
1 parent 136361e commit 5bc8f8b

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

www/docs/configuration/pages.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ SignIn.getInitialProps = async () => {
6565
If you create a custom sign in form for email sign in, you will need to submit both fields for the **email** address and **csrfToken** from **/api/auth/csrf** in a POST request to **/api/auth/signin/email**.
6666

6767
```jsx title="pages/auth/email-signin.js"
68-
import { csrfToken } from 'next-auth/client'
68+
import { getCsrfToken } from 'next-auth/client'
6969

7070
export default function SignIn({ csrfToken }) {
7171
return (
7272
<form method='post' action='/api/auth/signin/email'>
7373
<input name='csrfToken' type='hidden' defaultValue={csrfToken}/>
7474
<label>
7575
Email address
76-
<input type='text' id='email' name='email'/>
76+
<input type='email' id='email' name='email'/>
7777
</label>
7878
<button type='submit'>Sign in with Email</button>
7979
</form>
@@ -92,7 +92,7 @@ export async function getServerSideProps(context){
9292
// If older than Next.js 9.3
9393
SignIn.getInitialProps = async (context) => {
9494
return {
95-
csrfToken: await csrfToken(context)
95+
csrfToken: await getCsrfToken(context)
9696
}
9797
}
9898
*/
@@ -109,7 +109,7 @@ signIn('email', { email: '[email protected]' })
109109
If you create a sign in form for credentials based authentication, you will need to pass a **csrfToken** from **/api/auth/csrf** in a POST request to **/api/auth/callback/credentials**.
110110

111111
```jsx title="pages/auth/credentials-signin.js"
112-
import { csrfToken } from 'next-auth/client'
112+
import { getCsrfToken } from 'next-auth/client'
113113

114114
export default function SignIn({ csrfToken }) {
115115
return (
@@ -121,7 +121,7 @@ export default function SignIn({ csrfToken }) {
121121
</label>
122122
<label>
123123
Password
124-
<input name='password' type='text'/>
124+
<input name='password' type='password'/>
125125
</label>
126126
<button type='submit'>Sign in</button>
127127
</form>
@@ -141,7 +141,7 @@ export async function getServerSideProps(context) {
141141
// If older than Next.js 9.3
142142
SignIn.getInitialProps = async (context) => {
143143
return {
144-
csrfToken: await csrfToken(context)
144+
csrfToken: await getCsrfToken(context)
145145
}
146146
}
147147
*/

0 commit comments

Comments
 (0)