Skip to content

Commit

Permalink
Add generateRandomString function for generating random strings in au…
Browse files Browse the repository at this point in the history
…th.config.mjs for a user specific hash value
  • Loading branch information
taciturnaxolotl committed May 1, 2024
1 parent 63b6cce commit 57218d9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions auth.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ const logsnag = new LogSnag({
project: "magicsnap",
});

function generateRandomString() {
const chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let result = "";
for (let i = 0; i < 16; i++) {
const randomIndex = Math.floor(Math.random() * chars.length);
result += chars.charAt(randomIndex);
}
return result;
}

export default defineConfig({
providers: [
Slack({
Expand Down Expand Up @@ -50,6 +61,7 @@ export default defineConfig({
if (users.length === 0) {
await db.insert(User).values({
userId: profile["https://slack.com/user_id"],
hash: generateRandomString(),
name: profile.name,
email: profile.email,
image: profile.picture,
Expand Down Expand Up @@ -97,6 +109,7 @@ export default defineConfig({
} else {
await db.insert(User).values({
userId: profile["https://slack.com/user_id"],
hash: generateRandomString(),
name: profile.name,
email: profile.email,
image: profile.picture,
Expand Down
1 change: 1 addition & 0 deletions db/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const Organization = defineTable({
const User = defineTable({
columns: {
userId: column.text({ primaryKey: true }),
hash: column.text(),
team: column.text(),
name: column.text(),
email: column.text(),
Expand Down

0 comments on commit 57218d9

Please sign in to comment.