Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
lwjameson committed Nov 29, 2023
1 parent bc52fb0 commit 4292b61
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
4 changes: 4 additions & 0 deletions hold/.env.january-event
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SUPABASE_HOST=https://hnoejachzqwtzdovwljj.supabase.co
SUPABASE_SERVICE_KEY='eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imhub2VqYWNoenF3dHpkb3Z3bGpqIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTY5NDAxMDgwOSwiZXhwIjoyMDA5NTg2ODA5fQ.nbC4-g2vraSZRJCyfyTzuvRMSBp-O7N_eO4k-J6A95A'
SHARED_PASSWORD=$Workshop!2023
PROFESSOR_GROUP_ID='f918b2f8-f587-4ee1-9f2d-35b3aed0b1e6'
96 changes: 96 additions & 0 deletions hold/create-users-from-csv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
const Supa = require('@supabase/supabase-js');
const commandLineArgs = require('command-line-args');
const fs = require('fs');
const stream = require('stream');
const assert = require('assert');

const main = async (options) => {
let supabase = Supa.createClient(
process.env.SUPABASE_HOST,
process.env.SUPABASE_SERVICE_KEY,
{
auth: {
persistSession: false,
autoRefreshToken: false,
detectSessionInUrl: false,
},
}
);

const orgProfessorGroupResp = await supabase
.from('organization_groups')
.select()
.eq('id', process.env.PROFESSOR_GROUP_ID);

let str;
try {
str = fs.readFileSync(options.file, 'utf8');
} catch (err) {
console.error(err);
return;
}

const arr = str.split(/\r?\n/);

console.log(arr);

for (let i = 0; i < arr.length; i++) {
const username = arr[i];
if (username.length > 0) {
supabase = Supa.createClient(
process.env.SUPABASE_HOST,
process.env.SUPABASE_SERVICE_KEY,
{
auth: { persistSession: false },
}
);

const resp = await supabase.auth.admin.createUser({
email: username,
password: process.env.SHARED_PASSWORD,
});

if (!resp.error) {
console.log(`Login successfully created for user ${username}`);

let supabase = Supa.createClient(
process.env.SUPABASE_HOST,
process.env.SUPABASE_SERVICE_KEY,
{
auth: {
persistSession: false,
autoRefreshToken: false,
detectSessionInUrl: false,
},
}
);

const profile = await supabase
.from('profiles')
.select()
.eq('email', username);

// Add her to the Org Professors group
const groupUserResp = await supabase.from('group_users').insert({
type_id: orgProfessorGroupResp.data[0].id,
user_id: profile.data[0].id,
group_type: 'organization',
});

assert(groupUserResp.error === null);

console.log(`User ${username} added to Org Professor Group`);
} else {
console.error(
`Unable to create user: ${username}, error: ${resp.error}`
);
}
}
}
};

const optionDefinitions = [{ name: 'file', alias: 'f', type: String }];

const options = commandLineArgs(optionDefinitions);

main(options);
2 changes: 2 additions & 0 deletions hold/invites.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

[email protected]
Empty file.

0 comments on commit 4292b61

Please sign in to comment.