Skip to content

Commit

Permalink
Merge pull request #11 from kcoderhtml/remove-console-log
Browse files Browse the repository at this point in the history
remove-console-log-and-run-prettier
  • Loading branch information
kcoderhtml authored Apr 20, 2024
2 parents 54f03ca + 26edf5f commit 28278fe
Show file tree
Hide file tree
Showing 12 changed files with 186 additions and 158 deletions.
6 changes: 3 additions & 3 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import auth from "auth-astro";

// https://astro.build/config
export default defineConfig({
output: "server",
integrations: [tailwind(), db(), auth()],
adapter: netlify(),
output: "server",
integrations: [tailwind(), db(), auth()],
adapter: netlify(),
});
178 changes: 89 additions & 89 deletions auth.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,99 +3,99 @@ import { defineConfig } from "auth-astro";
import { db, like, User, Organization } from "astro:db";

export default defineConfig({
providers: [
Slack({
clientId: import.meta.env.SLACK_CLIENT_ID,
clientSecret: import.meta.env.SLACK_CLIENT_SECRET,
checks: ["pkce", "nonce"],
async profile(profile) {
const role = await db
.select()
.from(User)
.where(like(User.userId, profile["https://slack.com/user_id"]));
providers: [
Slack({
clientId: import.meta.env.SLACK_CLIENT_ID,
clientSecret: import.meta.env.SLACK_CLIENT_SECRET,
checks: ["pkce", "nonce"],
async profile(profile) {
const role = await db
.select()
.from(User)
.where(like(User.userId, profile["https://slack.com/user_id"]));

if (role.length === 0) {
const users = await db
.select()
.from(User)
.where(like(User.team, profile["https://slack.com/team_id"]));
if (role.length === 0) {
const users = await db
.select()
.from(User)
.where(like(User.team, profile["https://slack.com/team_id"]));

const organizations = await db
.select()
.from(Organization)
.where(
like(Organization.team, profile["https://slack.com/team_id"])
);
const organizations = await db
.select()
.from(Organization)
.where(
like(Organization.team, profile["https://slack.com/team_id"]),
);

// check if the user is part of an organization in the db by checking if the team id is the same
if (
organizations
.map((org) => org.team)
.includes(profile["https://slack.com/team_id"])
) {
if (users.length === 0) {
await db.insert(User).values({
userId: profile["https://slack.com/user_id"],
name: profile.name,
email: profile.email,
image: profile.picture,
team: profile["https://slack.com/team_id"],
role: "admin",
});
// check if the user is part of an organization in the db by checking if the team id is the same
if (
organizations
.map((org) => org.team)
.includes(profile["https://slack.com/team_id"])
) {
if (users.length === 0) {
await db.insert(User).values({
userId: profile["https://slack.com/user_id"],
name: profile.name,
email: profile.email,
image: profile.picture,
team: profile["https://slack.com/team_id"],
role: "admin",
});

role[0] = { role: "admin" };
} else {
await db.insert(User).values({
userId: profile["https://slack.com/user_id"],
name: profile.name,
email: profile.email,
image: profile.picture,
team: profile["https://slack.com/team_id"],
role: "user",
});
role[0] = { role: "admin" };
} else {
await db.insert(User).values({
userId: profile["https://slack.com/user_id"],
name: profile.name,
email: profile.email,
image: profile.picture,
team: profile["https://slack.com/team_id"],
role: "user",
});

role[0] = { role: "user" };
}
} else {
role[0] = { role: "guest" };
}
}
role[0] = { role: "user" };
}
} else {
role[0] = { role: "guest" };
}
}

return {
id: profile["https://slack.com/user_id"],
name: profile.name,
email: profile.email,
image: profile.picture,
team: profile["https://slack.com/team_id"],
teamName: profile["https://slack.com/team_name"],
teamImage: profile["https://slack.com/team_image_230"],
role: role[0].role || "user",
};
},
}),
],
callbacks: {
jwt({ token, user }) {
if (user) {
// User is available during sign-in
token.team = user.team;
token.teamName = user.teamName;
token.teamImage = user.teamImage;
token.role = user.role;
token.id = user.id;
}
return token;
},
session({ session, token }) {
if (token) {
// Token is available during sign-in
session.team = token.team;
session.teamName = token.teamName;
session.teamImage = token.teamImage;
session.user.role = token.role;
session.user.id = token.id;
}
return session;
},
},
return {
id: profile["https://slack.com/user_id"],
name: profile.name,
email: profile.email,
image: profile.picture,
team: profile["https://slack.com/team_id"],
teamName: profile["https://slack.com/team_name"],
teamImage: profile["https://slack.com/team_image_230"],
role: role[0].role || "user",
};
},
}),
],
callbacks: {
jwt({ token, user }) {
if (user) {
// User is available during sign-in
token.team = user.team;
token.teamName = user.teamName;
token.teamImage = user.teamImage;
token.role = user.role;
token.id = user.id;
}
return token;
},
session({ session, token }) {
if (token) {
// Token is available during sign-in
session.team = token.team;
session.teamName = token.teamName;
session.teamImage = token.teamImage;
session.user.role = token.role;
session.user.id = token.id;
}
return session;
},
},
});
Binary file modified bun.lockb
Binary file not shown.
19 changes: 9 additions & 10 deletions db/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { defineDb, defineTable, column } from 'astro:db';

import { defineDb, defineTable, column } from "astro:db";

const Organization = defineTable({
columns: {
Expand All @@ -9,8 +8,8 @@ const Organization = defineTable({
},
indexes: {
teamx: { on: ["team"], unique: true },
}
})
},
});

const User = defineTable({
columns: {
Expand All @@ -23,8 +22,8 @@ const User = defineTable({
},
indexes: {
userIdx: { on: ["userId"], unique: true },
}
})
},
});

const Event = defineTable({
columns: {
Expand All @@ -40,8 +39,8 @@ const Event = defineTable({
},
indexes: {
idx: { on: ["id"], unique: true },
}
})
},
});

const Invite = defineTable({
columns: {
Expand All @@ -51,8 +50,8 @@ const Invite = defineTable({
},
indexes: {
verificationCodeIdx: { on: ["verificationCode"], unique: true },
}
})
},
});

// https://astro.build/db/config
export default defineDb({
Expand Down
40 changes: 29 additions & 11 deletions db/seed.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
import { db, Invite, Event, Organization } from 'astro:db';
import { db, Invite, Event, Organization } from "astro:db";

// https://astro.build/db/seed
export default async function seed() {
await db.insert(Organization).values([
{ team: 'T0266FRGM', name: 'Hack Club', image: 'https://avatars.slack-edge.com/2022-04-01/3330920659891_26353517af684373601b_230.png' },
]);
await db.insert(Event).values([
{ team: 'T0266FRGM', name: 'Hackclub Meeting', comments: 'This is a test event', date: new Date(), location: 'Some location', statusGoing: '', statusMaybe: '', statusNotGoing: 'U062UG485EE' },
]);
await db.insert(Organization).values([
{
team: "T0266FRGM",
name: "Hack Club",
image:
"https://avatars.slack-edge.com/2022-04-01/3330920659891_26353517af684373601b_230.png",
},
]);
await db.insert(Event).values([
{
team: "T0266FRGM",
name: "Hackclub Meeting",
comments: "This is a test event",
date: new Date(),
location: "Some location",
statusGoing: "",
statusMaybe: "",
statusNotGoing: "U062UG485EE",
},
]);

await db.insert(Invite).values([
{ verificationCode: '123456', teamName: 'Hack Club', installationToken: 'xoxb-123456' },
]);
}
await db.insert(Invite).values([
{
verificationCode: "123456",
teamName: "Hack Club",
installationToken: "xoxb-123456",
},
]);
}
58 changes: 30 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
{
"name": "magicsnap",
"type": "module",
"version": "0.0.1",
"scripts": {
"dev": "astro dev",
"start": "astro dev",
"build": "astro check && astro build --remote",
"preview": "astro preview",
"astro": "astro"
},
"dependencies": {
"@astrojs/check": "^0.5.10",
"@astrojs/db": "^0.10.3",
"@astrojs/netlify": "^5.2.0",
"@astrojs/node": "^8.2.5",
"@astrojs/tailwind": "^5.1.0",
"@auth/core": "^0.18.6",
"astro": "^4.5.10",
"auth-astro": "^4.1.1",
"jwt-decode": "^4.0.0",
"magick.css": "^1.0.5",
"normalize.css": "^8.0.1",
"tailwindcss": "^3.4.2",
"typescript": "^5.4.3"
},
"devDependencies": {
"@types/bun": "^1.0.11"
}
"name": "magicsnap",
"type": "module",
"version": "0.0.1",
"scripts": {
"dev": "astro dev",
"start": "astro dev",
"build": "astro check && astro build --remote",
"preview": "astro preview",
"astro": "astro"
},
"dependencies": {
"@astrojs/check": "^0.5.10",
"@astrojs/db": "^0.10.3",
"@astrojs/netlify": "^5.2.0",
"@astrojs/node": "^8.2.5",
"@astrojs/tailwind": "^5.1.0",
"@auth/core": "^0.18.6",
"astro": "^4.5.10",
"auth-astro": "^4.1.1",
"jwt-decode": "^4.0.0",
"magick.css": "^1.0.5",
"normalize.css": "^8.0.1",
"prettier": "^3.2.5",
"prettier-plugin-astro": "^0.13.0",
"tailwindcss": "^3.4.2",
"typescript": "^5.4.3"
},
"devDependencies": {
"@types/bun": "^1.0.11"
}
}
20 changes: 19 additions & 1 deletion public/site.webmanifest
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
{"name":"","short_name":"","icons":[{"src":"/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"}
{
"name": "",
"short_name": "",
"icons": [
{
"src": "/android-chrome-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/android-chrome-512x512.png",
"sizes": "512x512",
"type": "image/png"
}
],
"theme_color": "#ffffff",
"background_color": "#ffffff",
"display": "standalone"
}
2 changes: 0 additions & 2 deletions src/components/ThreeWayToggle.astro
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ const { eventID, selected } = Astro.props;
radioButtons.forEach((radioButton) => {
radioButton.addEventListener("change", (event) => {
const selected = (event.target as HTMLInputElement).id;
console.log(selected.split("-")[1]);
console.log(defaultSelected);
if (selected.split("-")[1] != defaultSelected) {
submitButton.style.display = "block";
selectedInput.value = selected.split("-")[1];
Expand Down
Loading

0 comments on commit 28278fe

Please sign in to comment.