Skip to content

Commit 41467eb

Browse files
authored
Merge pull request #1183 from asleepynerd/main
Re-enable slack sign in for existing users.
2 parents e8aeb2e + d4abe1e commit 41467eb

File tree

3 files changed

+37
-36
lines changed

3 files changed

+37
-36
lines changed

src/app/api/slack_redirect/route.ts

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,45 @@ import { NextRequest } from 'next/server'
55
const errRedir = (err: any) => redirect('/slack-error?err=' + err.toString())
66

77
export async function GET(request: NextRequest) {
8-
return redirect('/slack-error?err=High Seas has ended! Sign-ups are disabled.')
9-
/*
8+
// Try to authenticate the user first
109
const code = request.nextUrl.searchParams.get('code')
11-
12-
const redirectUri = await getRedirectUri()
13-
14-
const exchangeUrl = `https://slack.com/api/openid.connect.token?code=${code}&client_id=${process.env.SLACK_CLIENT_ID}&client_secret=${process.env.SLACK_CLIENT_SECRET}&redirect_uri=${redirectUri}`
15-
console.log('exchanging by posting to', exchangeUrl)
16-
17-
const res = await fetch(exchangeUrl, { method: 'POST' })
18-
19-
if (res.status !== 200) return errRedir('Bad Slack OpenId response status')
20-
21-
let data
22-
try {
23-
data = await res.json()
24-
} catch (e) {
25-
console.error(e, await res.text())
26-
throw e
27-
}
28-
if (!data || !data.ok) {
29-
console.error(data)
30-
return errRedir('Bad Slack OpenID response')
10+
if (!code) {
11+
return redirect('/slack-error?err=Missing authorization code')
3112
}
3213

3314
try {
34-
await createSlackSession(data.id_token)
35-
console.log('cretaed slack session!! :)))))')
36-
} catch (e) {
37-
return errRedir(e)
15+
const redirectUri = await getRedirectUri()
16+
17+
const exchangeUrl = `https://slack.com/api/openid.connect.token?code=${code}&client_id=${process.env.SLACK_CLIENT_ID}&client_secret=${process.env.SLACK_CLIENT_SECRET}&redirect_uri=${redirectUri}`
18+
console.log('exchanging by posting to', exchangeUrl)
19+
20+
const res = await fetch(exchangeUrl, { method: 'POST' })
21+
22+
if (res.status !== 200) return errRedir('Bad Slack OpenId response status')
23+
24+
let data
25+
try {
26+
data = await res.json()
27+
} catch (e) {
28+
console.error(e, await res.text())
29+
throw e
30+
}
31+
if (!data || !data.ok) {
32+
console.error(data)
33+
return errRedir('Bad Slack OpenID response')
34+
}
35+
36+
try {
37+
await createSlackSession(data.id_token)
38+
console.log('created slack session!! :)))))')
39+
return redirect('/signpost')
40+
} catch (e: any) {
41+
if (e.toString().includes('Sign-ups are disabled')) {
42+
return errRedir(e)
43+
}
44+
throw e
45+
}
46+
} catch (error) {
47+
return errRedir(error)
3848
}
39-
40-
// const userInfoUrl = `https://slack.com/api/openid.connect.userInfo`;
41-
// const userInfo = await fetch(userInfoUrl, {
42-
// headers: { Authorization: `Bearer ${data.access_token}` },
43-
// }).then((d) => d.json());
44-
45-
redirect('/signpost')
46-
*/
4749
}

src/app/marketing/marketing-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export async function handleEmailSubmission(
2222
key: string
2323
} | null> {
2424
throw new Error('High Seas has ended! Sign-ups are disabled.')
25-
25+
2626
/*
2727
if (!email) throw new Error('No email supplied to handleEmailSubmission')
2828
if (!userAgent)

src/app/utils/server/auth.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ export async function createSlackSession(slackOpenidToken: string) {
105105
const person = (await getSelfPerson(payload.sub as string)) as any
106106

107107
if (!person) {
108-
// Sign-ups are disabled
109108
throw new Error('High Seas has ended! Sign-ups are disabled.')
110109

111110
/*

0 commit comments

Comments
 (0)