Skip to content

Commit fa7f6ef

Browse files
authored
Merge pull request #125 from hackclub/staging
let Jared log in
2 parents fe592e2 + 9900a0a commit fa7f6ef

3 files changed

Lines changed: 56 additions & 1 deletion

File tree

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ SLACK_TEAM=T0266FRGM
2222
# BETA_CHANNEL_ID=
2323

2424
SUPER_ADMIN_SLACK_ID=changeme
25+
LOGIN_IDV_BYPASS_SLACK_IDS="SLACK_ID_1,SLACK_ID_2"
2526

2627
IDV_DOMAIN=auth.hackclub.com
2728
IDV_CLIENT_ID=changeme

get-country-counts.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import Cryptr from 'cryptr';
2+
3+
const cryptr = new Cryptr('insert secret key here');
4+
5+
export function encrypt(plaintext: string) {
6+
return cryptr.encrypt(plaintext);
7+
}
8+
9+
export function decrypt(ciphertext: string) {
10+
return cryptr.decrypt(ciphertext);
11+
}
12+
13+
const tokens = [''];
14+
15+
export async function getUserData(token: string) {
16+
const userDataURL = new URL(`https://auth.hackclub.com/api/v1/me`);
17+
const userDataRes = await fetch(userDataURL, {
18+
method: 'GET',
19+
headers: {
20+
Authorization: `Bearer ${token}`
21+
}
22+
});
23+
24+
if (!userDataRes.ok) {
25+
throw new Error('Failed to fetch user data');
26+
}
27+
28+
const userDataJSON = await userDataRes.json();
29+
30+
return userDataJSON.identity!;
31+
}
32+
33+
const countries: Record<string, number> = {};
34+
35+
for (let i = 0; i < tokens.length; i++) {
36+
try {
37+
const token = decrypt(tokens[i]);
38+
const userData = await getUserData(token);
39+
const { addresses } = userData;
40+
const address = addresses?.find((address: { primary: boolean }) => address.primary);
41+
console.log('Address', i + '/' + tokens.length + ':', address.country);
42+
43+
countries[address.country as string] = (countries[address.country as string] ?? 0) + 1;
44+
} catch {
45+
console.warn('Failed: user ' + i);
46+
}
47+
}
48+
49+
console.log('\n');
50+
console.log(countries);

src/routes/auth/callback/+server.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ export async function GET(event) {
5555

5656
const { id, slack_id, first_name, last_name, primary_email, ysws_eligible } = userData;
5757

58-
if (!ysws_eligible) {
58+
if (
59+
!ysws_eligible &&
60+
(!env.LOGIN_IDV_BYPASS_SLACK_IDS ||
61+
!env.LOGIN_IDV_BYPASS_SLACK_IDS.split(',').includes(slack_id))
62+
) {
5963
return redirect(302, '/auth/ineligible');
6064
}
6165

0 commit comments

Comments
 (0)