-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
[email protected] |
Empty file.