|
1 | 1 | import NextAuth from 'next-auth' |
2 | 2 |
|
3 | | -export const authOptions = { |
| 3 | +export default NextAuth({ |
| 4 | + // Configure one or more authentication providers |
4 | 5 | providers: [ |
5 | 6 | { |
6 | | - id: 'openstreetmap', |
7 | | - name: 'openstreetmap', |
8 | | - clientId: process.env.OSM_CONSUMER_KEY, |
9 | | - clientSecret: process.env.OSM_CONSUMER_SECRET, |
| 7 | + id: 'osm-teams', |
| 8 | + name: 'OSM Teams', |
10 | 9 | type: 'oauth', |
11 | | - authorization: { |
12 | | - url: 'https://www.openstreetmap.org/oauth2/authorize', |
13 | | - params: { |
14 | | - scope: 'read_prefs', |
15 | | - }, |
16 | | - }, |
17 | | - token: 'https://www.openstreetmap.org/oauth2/token', |
18 | | - userinfo: 'https://api.openstreetmap.org/api/0.6/user/details.json', |
19 | | - profile({ user }) { |
| 10 | + wellKnown: |
| 11 | + 'https://auth.mapping.team/hyauth/.well-known/openid-configuration', |
| 12 | + authorization: { params: { scope: 'openid offline' } }, |
| 13 | + idToken: true, |
| 14 | + async profile(profile) { |
20 | 15 | return { |
21 | | - id: user.id, |
22 | | - name: user.display_name, |
23 | | - image: user.img?.href, |
| 16 | + id: profile.sub, |
| 17 | + name: profile.preferred_username, |
| 18 | + image: profile.picture, |
24 | 19 | } |
25 | 20 | }, |
| 21 | + clientId: process.env.OSM_TEAMS_CLIENT_ID, |
| 22 | + clientSecret: process.env.OSM_TEAMS_CLIENT_SECRET, |
26 | 23 | }, |
27 | 24 | ], |
28 | 25 | callbacks: { |
| 26 | + async jwt({ token, account, profile }) { |
| 27 | + // Persist the OAuth access_token and or the user id to the token right after signin |
| 28 | + if (account) { |
| 29 | + token.accessToken = account.access_token |
| 30 | + token.userId = profile.sub |
| 31 | + } |
| 32 | + return token |
| 33 | + }, |
29 | 34 | async session({ session, token }) { |
30 | | - // Add user id to session |
31 | | - const userId = parseInt(token.sub) |
32 | | - session.user_id = userId |
| 35 | + // Send properties to the client, like an access_token and user id from a provider. |
| 36 | + session.accessToken = token.accessToken |
| 37 | + session.user_id = token.userId |
33 | 38 | return session |
34 | 39 | }, |
35 | 40 | }, |
36 | | -} |
37 | | - |
38 | | -export default NextAuth(authOptions) |
| 41 | + // A database is optional, but required to persist accounts in a database |
| 42 | + database: process.env.DATABASE_URL, |
| 43 | +}) |
0 commit comments