Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ SLACK_TEAM=T0266FRGM
# BETA_CHANNEL_ID=

SUPER_ADMIN_SLACK_ID=changeme
LOGIN_IDV_BYPASS_SLACK_IDS="SLACK_ID_1,SLACK_ID_2"

IDV_DOMAIN=auth.hackclub.com
IDV_CLIENT_ID=changeme
Expand Down
50 changes: 50 additions & 0 deletions get-country-counts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import Cryptr from 'cryptr';

const cryptr = new Cryptr('insert secret key here');

export function encrypt(plaintext: string) {
return cryptr.encrypt(plaintext);
}

export function decrypt(ciphertext: string) {
return cryptr.decrypt(ciphertext);
}

const tokens = [''];

export async function getUserData(token: string) {
const userDataURL = new URL(`https://auth.hackclub.com/api/v1/me`);
const userDataRes = await fetch(userDataURL, {
method: 'GET',
headers: {
Authorization: `Bearer ${token}`
}
});

if (!userDataRes.ok) {
throw new Error('Failed to fetch user data');
}

const userDataJSON = await userDataRes.json();

return userDataJSON.identity!;
}

const countries: Record<string, number> = {};

for (let i = 0; i < tokens.length; i++) {
try {
const token = decrypt(tokens[i]);
const userData = await getUserData(token);
const { addresses } = userData;
const address = addresses?.find((address: { primary: boolean }) => address.primary);
console.log('Address', i + '/' + tokens.length + ':', address.country);

countries[address.country as string] = (countries[address.country as string] ?? 0) + 1;
} catch {
console.warn('Failed: user ' + i);
}
}

console.log('\n');
console.log(countries);
6 changes: 5 additions & 1 deletion src/routes/auth/callback/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ export async function GET(event) {

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

if (!ysws_eligible) {
if (
!ysws_eligible &&
(!env.LOGIN_IDV_BYPASS_SLACK_IDS ||
!env.LOGIN_IDV_BYPASS_SLACK_IDS.split(',').includes(slack_id))
) {
return redirect(302, '/auth/ineligible');
}

Expand Down
Loading