Skip to content

Commit

Permalink
Merge pull request #28 from kcoderhtml/dev
Browse files Browse the repository at this point in the history
feat: v0.2.1
  • Loading branch information
taciturnaxolotl authored Apr 29, 2024
2 parents b14230d + 5b041a0 commit ea0d93e
Show file tree
Hide file tree
Showing 10 changed files with 403 additions and 29 deletions.
114 changes: 110 additions & 4 deletions auth.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@ import Slack from "@auth/core/providers/slack";
import { defineConfig } from "auth-astro";
import { db, like, and, User, Organization } from "astro:db";

import { LogSnag } from "logsnag";

const logsnag = new LogSnag({
token: process.env.LOGSNAG_TOKEN || "",
project: "magicsnap",
});

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) {
let newUser = false;
profile["https://slack.com/team_id"] =
"slack-" + profile["https://slack.com/team_id"];

Expand Down Expand Up @@ -49,7 +57,43 @@ export default defineConfig({
role: "admin",
});

role[0] = { role: "admin" };
await logsnag.track({
channel: "signups",
event: "signup",
user_id: profile["https://slack.com/user_id"],
description: "User signed up as an admin",
icon: "🚀",
tags: {
team: profile["https://slack.com/team_id"],
role: "admin",
},
});

await logsnag.track({
channel: "actions",
event: "joined_team",
user_id: profile["https://slack.com/user_id"],
description: "User joined a team",
icon: "🤝",
tags: {
team: profile["https://slack.com/team_id"],
role: "admin",
},
});

await logsnag.identify({
user_id: profile["https://slack.com/user_id"],
properties: {
email: profile.email,
name: profile.name,
image: profile.picture,
team: profile["https://slack.com/team_id"],
role: "admin",
},
});

role[0].role = "admin";
newUser = true;
} else {
await db.insert(User).values({
userId: profile["https://slack.com/user_id"],
Expand All @@ -60,10 +104,69 @@ export default defineConfig({
role: "user",
});

role[0] = { role: "user" };
await logsnag.track({
channel: "signups",
event: "signup",
user_id: profile["https://slack.com/user_id"],
description: "User signed up as a user",
icon: "🚀",
tags: {
team: profile["https://slack.com/team_id"],
role: "user",
},
});

await logsnag.track({
channel: "actions",
event: "joined_team",
user_id: profile["https://slack.com/user_id"],
description: "User joined a team",
icon: "🤝",
tags: {
team: profile["https://slack.com/team_id"],
role: "user",
},
});

await logsnag.identify({
user_id: profile["https://slack.com/user_id"],
properties: {
email: profile.email,
name: profile.name,
image: profile.picture,
team: profile["https://slack.com/team_id"],
role: "user",
},
});

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

await logsnag.track({
channel: "signups",
event: "signup",
user_id: profile["https://slack.com/user_id"],
description: "User signed up as a guest",
icon: "🚀",
tags: {
team: profile["https://slack.com/team_id"],
role: "guest",
},
});

await logsnag.identify({
user_id: profile["https://slack.com/user_id"],
properties: {
email: profile.email,
name: profile.name,
image: profile.picture,
team: profile["https://slack.com/team_id"],
role: "guest",
},
});
}
}

Expand All @@ -75,7 +178,8 @@ export default defineConfig({
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",
role: role[0].role || "guest",
newUser: newUser,
};
},
}),
Expand All @@ -89,6 +193,7 @@ export default defineConfig({
token.teamImage = user.teamImage;
token.role = user.role;
token.id = user.id;
token.newUser = user.newUser;
}
return token;
},
Expand All @@ -100,6 +205,7 @@ export default defineConfig({
session.teamImage = token.teamImage;
session.user.role = token.role;
session.user.id = token.id;
session.newUser = token.newUser;
}
return session;
},
Expand Down
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions db/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const User = defineTable({
email: column.text(),
image: column.text(),
role: column.text(),
allergies: column.text({ optional: true }),
},
indexes: {
userIdx: { on: ["userId"], unique: true },
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
"@astrojs/node": "^8.2.5",
"@astrojs/tailwind": "^5.1.0",
"@auth/core": "^0.18.6",
"@types/canvas-confetti": "^1.6.4",
"astro": "^4.5.10",
"auth-astro": "^4.1.1",
"canvas-confetti": "^1.9.2",
"jwt-decode": "^4.0.0",
"logsnag": "^1.0.0",
"magick.css": "^1.0.5",
"normalize.css": "^8.0.1",
"prettier": "^3.2.5",
Expand Down
13 changes: 13 additions & 0 deletions src/pages/api/remind.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import type { APIRoute } from "astro"
import { db, User, Organization, Event } from "astro:db";
import { LogSnag } from "logsnag";

const logsnag = new LogSnag({
token: process.env.LOGSNAG_TOKEN || "",
project: "magicsnap",
});

export const POST: APIRoute = async ({ request }) => {
// get authorization header
Expand All @@ -20,6 +26,13 @@ export const POST: APIRoute = async ({ request }) => {
return diffHours < 24 && diffHours > 0
})

await logsnag.track({
channel: "api",
event: "reminder-sent",
description: `Sent reminder to ${users.length} users in ${organizations.length} different organizations about ${eventsHappeningToday.length} events happening today`,
icon: "📬",
});

return new Response(JSON.stringify({
ok: true, eventsHappeningToday: eventsHappeningToday, users: users, organizations: organizations
}), { status: 200 })
Expand Down
36 changes: 36 additions & 0 deletions src/pages/dashboard.astro
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type ExtendedSession = {
user: {
role: string;
};
newUser: boolean;
};
const session = (await getSession(Astro.request)) as Session & ExtendedSession;
Expand Down Expand Up @@ -44,6 +45,13 @@ if (!session) {
});
}
import { LogSnag } from "logsnag";
const logsnag = new LogSnag({
token: process.env.LOGSNAG_TOKEN || "",
project: "magicsnap",
});
import { db, Event, User } from "astro:db";
import { like } from "astro:db";
Expand Down Expand Up @@ -102,6 +110,13 @@ if (Astro.request.method === "POST") {
statusNotGoing: statusNotGoing.join(","),
})
.where(like(Event.id, eventID));
await logsnag.track({
channel: "actions",
event: "event_status_change",
icon: "📅",
user_id: session.user.id,
});
}
} else if (data.get("delete") != null) {
if (session.user.role != "admin") {
Expand All @@ -110,6 +125,13 @@ if (Astro.request.method === "POST") {
const eventID = data.get("eventID") as string;
await db.delete(Event).where(like(Event.id, eventID));
await logsnag.track({
channel: "actions",
event: "event_delete",
icon: "📅",
user_id: session.user.id,
});
}
else if (data.get("newEvent") != null) {
if (!data.has("name") || !data.has("date") || !data.has("time") || !data.has("location") || !data.has("comments")) {
Expand All @@ -135,6 +157,13 @@ if (Astro.request.method === "POST") {
.join(","),
};
await db.insert(Event).values(event);
await logsnag.track({
channel: "actions",
event: "event_create",
icon: "📅",
user_id: session.user.id,
});
}
} catch (error) {
if (error instanceof Error) {
Expand Down Expand Up @@ -165,6 +194,13 @@ const users = await db.select().from(User).where(like(User.team, session.team));
} events
</p>
</section>
{
session.newUser && (
<section>
<p>Since you are a new user we recommend that you first fillout your allergies <a href="/settings">here</a> then come back and set your availability!</p>
</section>
)
}
{
session.user.role === "admin" && (
<section>
Expand Down
Loading

0 comments on commit ea0d93e

Please sign in to comment.