Backend notification utility for API endpoints
cgen-c20fbebfac0d48579acc57e96d0f6700
This commit is contained in:
parent
c2f903b20f
commit
051a7f86d3
1 changed files with 39 additions and 0 deletions
39
api/_notifications.ts
Normal file
39
api/_notifications.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import { getAdminClient } from "./_supabase";
|
||||
|
||||
export async function createNotification(
|
||||
userId: string,
|
||||
type: string,
|
||||
title: string,
|
||||
message: string,
|
||||
): Promise<void> {
|
||||
try {
|
||||
const admin = getAdminClient();
|
||||
await admin.from("notifications").insert({
|
||||
user_id: userId,
|
||||
type,
|
||||
title,
|
||||
message,
|
||||
});
|
||||
} catch (error) {
|
||||
console.warn("Failed to create notification:", error);
|
||||
// Non-blocking - don't throw
|
||||
}
|
||||
}
|
||||
|
||||
export async function notifyAccountLinked(userId: string, provider: string): Promise<void> {
|
||||
await createNotification(
|
||||
userId,
|
||||
"success",
|
||||
`🔗 Account Linked: ${provider}`,
|
||||
`Your ${provider} account has been successfully linked.`,
|
||||
);
|
||||
}
|
||||
|
||||
export async function notifyOnboardingComplete(userId: string): Promise<void> {
|
||||
await createNotification(
|
||||
userId,
|
||||
"success",
|
||||
"🎉 Welcome to AeThex!",
|
||||
"You've completed your profile setup. Let's get started!",
|
||||
);
|
||||
}
|
||||
Loading…
Reference in a new issue