質問編集履歴

2

修正

2020/08/30 14:05

投稿

tomsuma
tomsuma

スコア38

test CHANGED
File without changes
test CHANGED
@@ -6,20 +6,346 @@
6
6
 
7
7
 
8
8
 
9
- [git](https://github.com/vercel/next.js/tree/canary/examples/with-firebase-hosting)
10
-
11
- このGitのとおりにインストールして始めようとしたのですが、
12
-
13
- いきなりのエラで諦ました、
14
-
15
-
16
-
17
- NextAuth.js用いた認証機能したのですが
18
-
19
- やはりいきなりのエラーであきらめました、、
20
-
21
-
22
-
23
- Next .jsでログイン機能は何を使えば一番手軽にできるでしょうか、、
24
-
25
- おすすめの記事やライブラリがあればご教授いただきたいです、、
9
+ next-auth-example
10
+
11
+ Template
12
+
13
+ コピして始めたのですが
14
+
15
+ mysqlにデータベースを設定し、
16
+
17
+ メールアドレス登録登録ようとしたのですがこのようなエラーが出ました、、
18
+
19
+
20
+
21
+ コレはどこに何が足りないのでしょうか、、
22
+
23
+ ```
24
+
25
+ https://next-auth.js.org/errors#adapter_connection_error
26
+
27
+ (node:3472) UnhandledPromiseRejectionWarning: TypeError: Cannot destructure property 'manager' of 'connection' as it is null.
28
+
29
+ at Object.<anonymous> (/Users/user/projects/matching/node_modules/next-auth/dist/adapters/typeorm/index.js:102:9)
30
+
31
+ at Generator.next (<anonymous>)
32
+
33
+ at asyncGeneratorStep (/Users/user/projects/matching/node_modules/next-auth/dist/adapters/typeorm/index.js:28:103)
34
+
35
+ at _next (/Users/user/projects/matching/node_modules/next-auth/dist/adapters/typeorm/index.js:30:194)
36
+
37
+ at runMicrotasks (<anonymous>)
38
+
39
+ at processTicksAndRejections (internal/process/task_queues.js:97:5)
40
+
41
+ (node:3472) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 6)
42
+
43
+ ```
44
+
45
+
46
+
47
+ データベースの変更は[github](https://github.com/nextauthjs/next-auth-example)を参考にやらせてもらったつもりです
48
+
49
+ ```
50
+
51
+ メールアドレス登録時のユーアールエル
52
+
53
+ https://next-auth-example.now.sh/api/auth/signin?callbackUrl=https%3A%2F%2Fnext-auth-example.now.sh%2F
54
+
55
+ ```
56
+
57
+
58
+
59
+
60
+
61
+ ```
62
+
63
+
64
+
65
+ [next-auth-example].js
66
+
67
+
68
+
69
+ import NextAuth from 'next-auth'
70
+
71
+ import Providers from 'next-auth/providers'
72
+
73
+
74
+
75
+ // For more information on each option (and a full list of options) go to
76
+
77
+ // https://next-auth.js.org/configuration/options
78
+
79
+ const options = {
80
+
81
+ // https://next-auth.js.org/configuration/providers
82
+
83
+ providers: [
84
+
85
+ Providers.Email({
86
+
87
+ server: process.env.EMAIL_SERVER,
88
+
89
+ from: process.env.EMAIL_FROM,
90
+
91
+ }),
92
+
93
+ Providers.Apple({
94
+
95
+ clientId: process.env.APPLE_ID,
96
+
97
+ clientSecret: {
98
+
99
+ appleId: process.env.APPLE_ID,
100
+
101
+ teamId: process.env.APPLE_TEAM_ID,
102
+
103
+ privateKey: process.env.APPLE_PRIVATE_KEY,
104
+
105
+ keyId: process.env.APPLE_KEY_ID,
106
+
107
+ }
108
+
109
+ }),
110
+
111
+ Providers.Auth0({
112
+
113
+ clientId: process.env.AUTH0_ID,
114
+
115
+ clientSecret: process.env.AUTH0_SECRET,
116
+
117
+ domain: process.env.AUTH0_DOMAIN
118
+
119
+ }),
120
+
121
+ Providers.Facebook({
122
+
123
+ clientId: process.env.FACEBOOK_ID,
124
+
125
+ clientSecret: process.env.FACEBOOK_SECRET
126
+
127
+ }),
128
+
129
+ Providers.GitHub({
130
+
131
+ clientId: process.env.GITHUB_ID,
132
+
133
+ clientSecret: process.env.GITHUB_SECRET
134
+
135
+ }),
136
+
137
+ Providers.Google({
138
+
139
+ clientId: process.env.GOOGLE_ID,
140
+
141
+ clientSecret: process.env.GOOGLE_SECRET
142
+
143
+ }),
144
+
145
+ Providers.Twitter({
146
+
147
+ clientId: process.env.TWITTER_ID,
148
+
149
+ clientSecret: process.env.TWITTER_SECRET
150
+
151
+ }),
152
+
153
+ ],
154
+
155
+ // Database optional. MySQL, Maria DB, Postgres and MongoDB are supported.
156
+
157
+ // https://next-auth.js.org/configuration/database
158
+
159
+ //
160
+
161
+ // Notes:
162
+
163
+ // * You must to install an appropriate node_module for your database
164
+
165
+ // * The Email provider requires a database (OAuth providers do not)
166
+
167
+ database: process.env.DATABASE_URL,
168
+
169
+
170
+
171
+ // The secret should be set to a reasonably long random string.
172
+
173
+ // It is used to sign cookies and to sign and encrypt JSON Web Tokens, unless
174
+
175
+ // a seperate secret is defined explicitly for encrypting the JWT.
176
+
177
+ secret: process.env.SECRET,
178
+
179
+
180
+
181
+ session: {
182
+
183
+ // Use JSON Web Tokens for session instead of database sessions.
184
+
185
+ // This option can be used with or without a database for users/accounts.
186
+
187
+ // Note: `jwt` is automatically set to `true` if no database is specified.
188
+
189
+ jwt: true,
190
+
191
+
192
+
193
+ // Seconds - How long until an idle session expires and is no longer valid.
194
+
195
+ // maxAge: 30 * 24 * 60 * 60, // 30 days
196
+
197
+
198
+
199
+ // Seconds - Throttle how frequently to write to database to extend a session.
200
+
201
+ // Use it to limit write operations. Set to 0 to always update the database.
202
+
203
+ // Note: This option is ignored if using JSON Web Tokens
204
+
205
+ // updateAge: 24 * 60 * 60, // 24 hours
206
+
207
+ },
208
+
209
+
210
+
211
+ // JSON Web tokens are only used for sessions if the `jwt: true` session
212
+
213
+ // option is set - or by default if no database is specified.
214
+
215
+ // https://next-auth.js.org/configuration/options#jwt
216
+
217
+ jwt: {
218
+
219
+ // A secret to use for key generation (you should set this explicitly)
220
+
221
+ // secret: 'INp8IvdIyeMcoGAgFGoA61DdBglwwSqnXJZkgz8PSnw',
222
+
223
+
224
+
225
+ // Set to true to use encryption (default: false)
226
+
227
+ // encryption: true,
228
+
229
+
230
+
231
+ // You can define your own encode/decode functions for signing and encryption
232
+
233
+ // if you want to override the default behaviour.
234
+
235
+ // encode: async ({ secret, token, maxAge }) => {},
236
+
237
+ // decode: async ({ secret, token, maxAge }) => {},
238
+
239
+ },
240
+
241
+
242
+
243
+ // You can define custom pages to override the built-in pages.
244
+
245
+ // The routes shown here are the default URLs that will be used when a custom
246
+
247
+ // pages is not specified for that route.
248
+
249
+ // https://next-auth.js.org/configuration/pages
250
+
251
+ pages: {
252
+
253
+ // signIn: '/api/auth/signin', // Displays signin buttons
254
+
255
+ // signOut: '/api/auth/signout', // Displays form with sign out button
256
+
257
+ // error: '/api/auth/error', // Error code passed in query string as ?error=
258
+
259
+ // verifyRequest: '/api/auth/verify-request', // Used for check email page
260
+
261
+ // newUser: null // If set, new users will be directed here on first sign in
262
+
263
+ },
264
+
265
+
266
+
267
+ // Callbacks are asynchronous functions you can use to control what happens
268
+
269
+ // when an action is performed.
270
+
271
+ // https://next-auth.js.org/configuration/callbacks
272
+
273
+ callbacks: {
274
+
275
+ // signIn: async (user, account, profile) => { return Promise.resolve(true) },
276
+
277
+ // redirect: async (url, baseUrl) => { return Promise.resolve(baseUrl) },
278
+
279
+ // session: async (session, user) => { return Promise.resolve(session) },
280
+
281
+ // jwt: async (token, user, account, profile, isNewUser) => { return Promise.resolve(token) }
282
+
283
+ },
284
+
285
+
286
+
287
+ // Events are useful for logging
288
+
289
+ // https://next-auth.js.org/configuration/events
290
+
291
+ events: { },
292
+
293
+
294
+
295
+ // Enable debug messages in the console if you are having problems
296
+
297
+ debug: false,
298
+
299
+ }
300
+
301
+
302
+
303
+ export default (req, res) => NextAuth(req, res, options)
304
+
305
+
306
+
307
+ ```
308
+
309
+
310
+
311
+
312
+
313
+ ```
314
+
315
+ .env.local
316
+
317
+ NEXTAUTH_URL=http://localhost:3000
318
+
319
+ SECRET=
320
+
321
+ AUTH0_ID=
322
+
323
+ AUTH0_SECRET=
324
+
325
+ AUTH0_DOMAIN=
326
+
327
+ FACEBOOK_ID=
328
+
329
+ FACEBOOK_SECRET=
330
+
331
+ GITHUB_ID=
332
+
333
+ GITHUB_SECRET=
334
+
335
+ GOOGLE_ID=
336
+
337
+ GOOGLE_SECRET=
338
+
339
+ TWITTER_ID=
340
+
341
+ TWITTER_SECRET=
342
+
343
+ EMAIL_SERVER=smtp://username:password@smtp.example.com.com:587
344
+
345
+ EMAIL_FROM=NextAuth <noreply@example.com>
346
+
347
+ DATABASE_URL=mysql://username:password@127.0.0.1:3306/database_name?synchronize=true
348
+
349
+
350
+
351
+ ```

1

修正

2020/08/30 14:05

投稿

tomsuma
tomsuma

スコア38

test CHANGED
@@ -1 +1 @@
1
- Next.js ログイン機能につ
1
+ Next.js ログイン機能を実装した!!
test CHANGED
@@ -2,276 +2,24 @@
2
2
 
3
3
 
4
4
 
5
- NextAuth.jsというパッケージを使えば認証機能がデータベース無しで実現できるというのを知り、早速公式ドキュメントどうりにやってみたのですが、
6
-
7
- 早速500エラーが出てきて止まっています[NextAuth.jsドキュメント](https://next-auth.js.org/getting-started/example)
8
-
9
- 新しい状態からはじめて3つのファルの書き換えしか行っていないの
5
+ next.jsでログン機能を作ろう
10
-
11
- importで使っていたパッケージはすべてインストールしたので間違えていないはずなのですが、どうしてでしょうか、、、
12
6
 
13
7
 
14
8
 
9
+ [git](https://github.com/vercel/next.js/tree/canary/examples/with-firebase-hosting)
10
+
15
- next.jsでログイン機能を実装したいだけなのでNextAuth.jsにあまりこだわりはないです、
11
+ このGitのとおりにインストールて始めようとしたのです
12
+
13
+ いきなりのエラーで諦めました、、
16
14
 
17
15
 
18
16
 
19
- ```
17
+ NextAuth.jsを用いた認証機能を試したのですが
20
18
 
21
- pages/index.js
19
+ やはりいきなりのエラーであきらめました、、
22
20
 
23
21
 
24
22
 
23
+ Next .jsでログイン機能は何を使えば一番手軽にできるでしょうか、、
25
24
 
26
-
27
- import Head from 'next/head'
28
-
29
- import styles from '../styles/Home.module.css'
30
-
31
- import React from 'react'
32
-
33
- import { signIn, signOut, useSession } from 'next-auth/client'
34
-
35
-
36
-
37
- export default function Page() {
38
-
39
- const [ session, loading ] = useSession()
40
-
41
-
42
-
43
- return <>
44
-
45
- {!session && <>
46
-
47
- Not signed in <br/>
25
+ おすすめの記事やライブラリがあればご教授いただきたいです、、
48
-
49
- <button onClick={signIn}>Sign in</button>
50
-
51
- </>}
52
-
53
- {session && <>
54
-
55
- Signed in as {session.user.email} <br/>
56
-
57
- <button onClick={signOut}>Sign out</button>
58
-
59
- </>}
60
-
61
- </>
62
-
63
- }
64
-
65
- export default function Home() {
66
-
67
- return (
68
-
69
- <div className={styles.container}>
70
-
71
- <Head>
72
-
73
- <title>Create Next App</title>
74
-
75
- <link rel="icon" href="/favicon.ico" />
76
-
77
- </Head>
78
-
79
-
80
-
81
- <main className={styles.main}>
82
-
83
- <h1 className={styles.title}>
84
-
85
- Welcome to <a href="https://nextjs.org">Next.js!</a>
86
-
87
- </h1>
88
-
89
-
90
-
91
- <p className={styles.description}>
92
-
93
- Get started by editing{' '}
94
-
95
- <code className={styles.code}>pages/index.js</code>
96
-
97
- </p>
98
-
99
-
100
-
101
- <div className={styles.grid}>
102
-
103
- <a href="https://nextjs.org/docs" className={styles.card}>
104
-
105
- <h3>Documentation &rarr;</h3>
106
-
107
- <p>Find in-depth information about Next.js features and API.</p>
108
-
109
- </a>
110
-
111
-
112
-
113
- <a href="https://nextjs.org/learn" className={styles.card}>
114
-
115
- <h3>Learn &rarr;</h3>
116
-
117
- <p>Learn about Next.js in an interactive course with quizzes!</p>
118
-
119
- </a>
120
-
121
-
122
-
123
- <a
124
-
125
- href="https://github.com/vercel/next.js/tree/master/examples"
126
-
127
- className={styles.card}
128
-
129
- >
130
-
131
- <h3>Examples &rarr;</h3>
132
-
133
- <p>Discover and deploy boilerplate example Next.js projects.</p>
134
-
135
- </a>
136
-
137
-
138
-
139
- <a
140
-
141
- href="https://vercel.com/import?filter=next.js&utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
142
-
143
- className={styles.card}
144
-
145
- >
146
-
147
- <h3>Deploy &rarr;</h3>
148
-
149
- <p>
150
-
151
- Instantly deploy your Next.js site to a public URL with Vercel.
152
-
153
- </p>
154
-
155
- </a>
156
-
157
- </div>
158
-
159
- </main>
160
-
161
-
162
-
163
- <footer className={styles.footer}>
164
-
165
- <a
166
-
167
- href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
168
-
169
- target="_blank"
170
-
171
- rel="noopener noreferrer"
172
-
173
- >
174
-
175
- Powered by{' '}
176
-
177
- <img src="/vercel.svg" alt="Vercel Logo" className={styles.logo} />
178
-
179
- </a>
180
-
181
- </footer>
182
-
183
- </div>
184
-
185
- )
186
-
187
- }
188
-
189
-
190
-
191
- ```
192
-
193
- ```
194
-
195
- [...nextauth].js
196
-
197
-
198
-
199
-
200
-
201
- import NextAuth from 'next-auth'
202
-
203
- import Providers from 'next-auth/providers'
204
-
205
-
206
-
207
- const options = {
208
-
209
- // Configure one or more authentication providers
210
-
211
- providers: [
212
-
213
- Providers.GitHub({
214
-
215
- clientId: process.env.GITHUB_ID,
216
-
217
- clientSecret: process.env.GITHUB_SECRET
218
-
219
- }),
220
-
221
- // ...add more providers here
222
-
223
- ],
224
-
225
-
226
-
227
- // A database is optional, but required to persist accounts in a database
228
-
229
- database: process.env.DATABASE_URL,
230
-
231
- }
232
-
233
-
234
-
235
- export default (req, res) => NextAuth(req, res, options)
236
-
237
- ```
238
-
239
- ```
240
-
241
- _app.js
242
-
243
-
244
-
245
- import '../styles/globals.css'
246
-
247
- import { Provider } from 'next-auth/client'
248
-
249
-
250
-
251
- export default function App ({ Component, pageProps }) {
252
-
253
- return (
254
-
255
- <Provider session={pageProps.session}>
256
-
257
- <Component {...pageProps} />
258
-
259
- </Provider>
260
-
261
- )
262
-
263
- }
264
-
265
- function MyApp({ Component, pageProps }) {
266
-
267
- return <Component {...pageProps} />
268
-
269
- }
270
-
271
-
272
-
273
- export default MyApp
274
-
275
-
276
-
277
- ```