Skip to content

Commit 5fd3ce0

Browse files
committed
sign in with auth.mapping.team
1 parent 8a121ba commit 5fd3ce0

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

src/components/sidebar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ export default function Sidebar() {
285285
) : (
286286
<Button
287287
className='global-menu__link login'
288-
onClick={() => signIn('openstreetmap')}
288+
onClick={() => signIn('osm-teams')}
289289
>
290290
Sign in
291291
</Button>

src/pages/api/auth/[...nextauth].js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import NextAuth from 'next-auth'
2+
import { mergeDeepRight } from 'ramda'
3+
const db = require('../../../lib/db')
24

3-
export default NextAuth({
5+
export const authOptions = {
46
// Configure one or more authentication providers
57
providers: [
68
{
@@ -38,6 +40,26 @@ export default NextAuth({
3840
return session
3941
},
4042
},
41-
// A database is optional, but required to persist accounts in a database
42-
database: process.env.DATABASE_URL,
43-
})
43+
44+
events: {
45+
async signIn({ profile }) {
46+
// On successful sign in we should persist the user to the database
47+
let [user] = await db('users').where('id', profile.id)
48+
if (user) {
49+
const newProfile = mergeDeepRight(user.profile, profile)
50+
await db('users')
51+
.where('id', profile.id)
52+
.update({
53+
profile: JSON.stringify(newProfile),
54+
})
55+
} else {
56+
await db('users').insert({
57+
id: profile.id,
58+
profile: JSON.stringify(profile),
59+
})
60+
}
61+
},
62+
},
63+
}
64+
65+
export default NextAuth(authOptions)

src/pages/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ export default function Home() {
207207
</Button>
208208
</div>
209209
) : (
210-
<Button onClick={() => signIn('openstreetmap')}>Sign in →</Button>
210+
<Button onClick={() => signIn('osm-teams')}>Sign in →</Button>
211211
)}
212212
</div>
213213
<div className='map-bg' />

src/pages/teams/[id]/invitations/[invitationId].js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default function TeamInvitationPage({ errorCode, errorMessage }) {
2121
<article className='inner page'>
2222
<section>
2323
<h1>Please sign in</h1>
24-
<Button onClick={() => signIn('openstreetmap')}>Sign in →</Button>
24+
<Button onClick={() => signIn('osm-teams')}>Sign in →</Button>
2525
</section>
2626
</article>
2727
)

0 commit comments

Comments
 (0)