-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
index.js
251 lines (241 loc) · 7.69 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
import React from 'react'
import classnames from 'classnames'
import Layout from '@theme/Layout'
import Link from '@docusaurus/Link'
import useDocusaurusContext from '@docusaurus/useDocusaurusContext'
import useBaseUrl from '@docusaurus/useBaseUrl'
import CodeBlock from '@theme/CodeBlock'
import ProviderMarquee from '../components/ProviderMarquee'
import Seo from './seo'
import styles from './styles.module.css'
const features = [
{
title: 'Easy',
imageUrl: 'img/undraw_social.svg',
description: (
<ul>
<li>Built in support for popular services<br />
<em>(Google, Facebook, Auth0, Apple…)</em>
</li>
<li>Built in email / passwordless / magic link</li>
<li>Use with any username / password store</li>
<li>Use with OAuth 1.0 & 2.0 services</li>
</ul>
)
},
{
title: 'Flexible',
imageUrl: 'img/undraw_authentication.svg',
description: (
<ul>
<li>Built for Serverless, runs anywhere</li>
<li>
Bring Your Own Database - or none!<br />
<em>(MySQL, Postgres, MSSQL, MongoDB…)</em>
</li>
<li>Choose database sessions or JWT</li>
<li>Secure web pages and API routes</li>
</ul>
)
},
{
title: 'Secure',
imageUrl: 'img/undraw_secure.svg',
description: (
<ul>
<li>Signed, prefixed, server-only cookies</li>
<li>HTTP POST + CSRF Token validation</li>
<li>JWT with JWS / JWE / JWK / JWK</li>
<li>Tab syncing, auto-revalidation, keepalives</li>
<li>Doesn't rely on client side JavaScript</li>
</ul>
)
}
]
function Feature ({ imageUrl, title, description }) {
const imgUrl = useBaseUrl(imageUrl)
return (
<div className={classnames('col col--4', styles.feature)}>
{imgUrl && (
<div className='text--center'>
<div className='feature-image-wrapper'>
<img className={styles.featureImage} src={imgUrl} alt={title} />
</div>
</div>
)}
<h3 className='text--center'>{title}</h3>
<p>{description}</p>
</div>
)
}
function Home () {
const context = useDocusaurusContext()
const { siteConfig = {} } = context
return (
<Layout description={siteConfig.tagline}>
<Seo />
<div className='home-wrapper'>
<header className={classnames('hero', styles.heroBanner)}>
<div className='container'>
<div className='hero-inner'>
<img
src='/img/logo/logo-sm.png'
alt='Shield with key icon'
className={styles.heroLogo}
/>
<div className={styles.heroText}>
<h1 className='hero__title'>{siteConfig.title}</h1>
<p className='hero__subtitle'>{siteConfig.tagline}</p>
</div>
<div className={styles.buttons}>
<a
className={classnames(
'button button--outline button--secondary button--lg rounded-pill',
styles.button
)}
href='https://next-auth-example.now.sh'
>Live Demo
</a>
<Link
className={classnames(
'button button--primary button--lg rounded-pill',
styles.button
)}
to={useBaseUrl('/getting-started/example')}
>Get Started
</Link>
</div>
</div>
<div className='hero-marquee'>
<ProviderMarquee />
</div>
</div>
<div className='hero-wave'>
<div className='hero-wave-inner' />
</div>
</header>
<main className='home-main'>
<section className={`section-features ${styles.features}`}>
<div className='container'>
<div className='row'>
<div className='col'>
<h2 className={styles.featuresTitle}>
<span>Open Source.</span> <span>Full Stack.</span> <span>Own Your Data.</span>
</h2>
</div>
</div>
<div className='row'>
{features.map((props, idx) => (
<Feature key={idx} {...props} />
))}
</div>
</div>
</section>
<section>
<div className='container'>
<div className='row'>
<div className='col'>
<p className='text--center'>
<a
href='https://www.npmjs.com/package/next-auth'
className='button button--primary button--outline rounded-pill button--lg'
>npm install next-auth
</a>
</p>
</div>
</div>
<div className='row'>
<div className='col'>
<h2 className='text--center'>
Add authentication in minutes!
</h2>
</div>
</div>
<div className='row'>
<div className='col col--6'>
<div className='code'>
<h4 className='code-heading'>Server</h4>
<CodeBlock className='javascript'>{serverlessFunctionCode}</CodeBlock>
</div>
</div>
<div className='col col--6'>
<div className='code'>
<h4 className='code-heading'>Client</h4>
<CodeBlock className='javascript'>{reactComponentCode}</CodeBlock>
</div>
</div>
</div>
<div className='row'>
<div className='col'>
<p className='text--center' style={{ marginTop: '2rem' }}>
<Link
to='/getting-started/example'
className='button button--primary button--lg rounded-pill'
>Get Started
</Link>
</p>
</div>
</div>
</div>
</section>
<div className='container'>
<div className='row home-subtitle'>
{siteConfig.title} is not affiliated with Vercel or Next.js
</div>
</div>
</main>
</div>
</Layout>
)
}
const reactComponentCode = `
import React from 'react'
import {
signIn,
signOut,
useSession
} from 'next-auth/client'
export default function myComponent() {
const [ session, loading ] = useSession()
return <>
{!session && <>
Not signed in <br/>
<button onClick={signIn}>Sign in</button>
</>}
{session && <>
Signed in as {session.user.email} <br/>
<button onClick={signOut}>Sign out</button>
</>}
</>
}
`.trim()
const serverlessFunctionCode = `
import NextAuth from 'next-auth'
import Providers from 'next-auth/providers'
const options = {
providers: [
// OAuth authentication providers
Providers.Apple({
clientId: process.env.APPLE_ID,
clientSecret: process.env.APPLE_SECRET
}),
Providers.Facebook({
clientId: process.env.FACEBOOK_ID,
clientSecret: process.env.FACEBOOK_SECRET
}),
Providers.Google({
clientId: process.env.GOOGLE_ID,
clientSecret: process.env.GOOGLE_SECRET
}),
// Sign in with email
Providers.Email({
server: process.env.MAIL_SERVER,
from: 'NextAuth.js <no-reply@example.com>'
}),
],
// SQL or MongoDB database (or leave empty)
database: process.env.DATABASE_URL
}
export default (req, res) => NextAuth(req, res, options)
`.trim()
export default Home