Skip to content

Commit

Permalink
fix: remove agent access automation
Browse files Browse the repository at this point in the history
  • Loading branch information
p10e committed Jun 25, 2024
1 parent 3ba72f0 commit 37fdf21
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions api/callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { VercelRequest, VercelResponse } from '@vercel/node'
import fetch from 'axios'

import { contributor } from './_roles/contributor'
import { agent } from './_roles/agent'
import OAuth2 from './_utils/oauth'

const sanityOAuth2 = OAuth2({
Expand Down Expand Up @@ -94,11 +93,7 @@ export default async function callback(req: VercelRequest, res: VercelResponse)
}).then((res) => res.data)

const role =
(profile.provider === 'google' && profile.email.endsWith('@sanity.io')) ||
(profile.provider === 'github' && profile.email === process.env.SANITY_TOKEN_A) ||
(profile.provider === 'github' && profile.email === process.env.SANITY_TOKEN_B)
? 'agent'
: 'editor'
profile.provider === 'google' && profile.email.endsWith('@sanity.io') ? 'agent' : 'editor'

const user = userFromProfile(profile, role)

Expand All @@ -122,17 +117,15 @@ export default async function callback(req: VercelRequest, res: VercelResponse)
}
})

await sessionClient
.createIfNotExists(role === 'agent' ? agent : contributor)
.then((group: any) => {
if (!(group.members || []).includes(user.userId)) {
return sessionClient
.patch(group._id)
.setIfMissing({ members: [] })
.append('members', [user.userId])
.commit()
}
})
await sessionClient.createIfNotExists(contributor).then((group: any) => {
if (!(group.members || []).includes(user.userId)) {
return sessionClient
.patch(group._id)
.setIfMissing({ members: [] })
.append('members', [user.userId])
.commit()
}
})

const { sid } = await sessionClient.request({
uri: '/auth/thirdParty/session',
Expand Down

0 comments on commit 37fdf21

Please sign in to comment.