-
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
7 changed files
with
137 additions
and
28 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
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
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,10 @@ | ||
const authConfig = { | ||
providers: [ | ||
{ | ||
domain: "https://evident-skink-35.clerk.accounts.dev", | ||
applicationID: "convex", | ||
}, | ||
] | ||
}; | ||
|
||
export default authConfig; |
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,72 @@ | ||
// ===== reference links ===== | ||
// https://www.convex.dev/templates (open the link and choose for clerk than you will get the github link mentioned below) | ||
// https://github.dev/webdevcody/thumbnail-critique/blob/6637671d72513cfe13d00cb7a2990b23801eb327/convex/schema.ts | ||
|
||
import type { WebhookEvent } from "@clerk/nextjs/server"; | ||
import { httpRouter } from "convex/server"; | ||
import { Webhook } from "svix"; | ||
|
||
import { internal } from "./_generated/api"; | ||
import { httpAction } from "./_generated/server"; | ||
|
||
const handleClerkWebhook = httpAction(async (ctx, request) => { | ||
const event = await validateRequest(request); | ||
if (!event) { | ||
return new Response("Invalid request", { status: 400 }); | ||
} | ||
switch (event.type) { | ||
case "user.created": | ||
await ctx.runMutation(internal.users.createUser, { | ||
clerkId: event.data.id, | ||
email: event.data.email_addresses[0].email_address, | ||
imageUrl: event.data.image_url, | ||
name: event.data.first_name as string, | ||
}); | ||
break; | ||
case "user.updated": | ||
await ctx.runMutation(internal.users.updateUser, { | ||
clerkId: event.data.id, | ||
imageUrl: event.data.image_url, | ||
email: event.data.email_addresses[0].email_address, | ||
}); | ||
break; | ||
case "user.deleted": | ||
await ctx.runMutation(internal.users.deleteUser, { | ||
clerkId: event.data.id as string, | ||
}); | ||
break; | ||
} | ||
return new Response(null, { | ||
status: 200, | ||
}); | ||
}); | ||
|
||
const http = httpRouter(); | ||
|
||
http.route({ | ||
path: "/clerk", | ||
method: "POST", | ||
handler: handleClerkWebhook, | ||
}); | ||
|
||
const validateRequest = async ( | ||
req: Request | ||
): Promise<WebhookEvent | undefined> => { | ||
// key note : add the webhook secret variable to the environment variables field in convex dashboard setting | ||
const webhookSecret = process.env.CLERK_WEBHOOK_SECRET!; | ||
if (!webhookSecret) { | ||
throw new Error("CLERK_WEBHOOK_SECRET is not defined"); | ||
} | ||
const payloadString = await req.text(); | ||
const headerPayload = req.headers; | ||
const svixHeaders = { | ||
"svix-id": headerPayload.get("svix-id")!, | ||
"svix-timestamp": headerPayload.get("svix-timestamp")!, | ||
"svix-signature": headerPayload.get("svix-signature")!, | ||
}; | ||
const wh = new Webhook(webhookSecret); | ||
const event = wh.verify(payloadString, svixHeaders); | ||
return event as unknown as WebhookEvent; | ||
}; | ||
|
||
export default http; |
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { query } from "./_generated/server"; | ||
/*import { query } from "./_generated/server"; | ||
export const get = query({ | ||
args: {}, | ||
handler: async (ctx) => { | ||
return await ctx.db.query("tasks").collect(); | ||
}, | ||
}); | ||
});*/ |
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,31 @@ | ||
"use client"; | ||
|
||
import { ReactNode } from "react"; | ||
import { ClerkProvider, useAuth } from "@clerk/nextjs"; | ||
import { ConvexProviderWithClerk } from "convex/react-clerk"; | ||
import { ConvexReactClient } from "convex/react"; | ||
|
||
const convex = new ConvexReactClient(process.env.NEXT_PUBLIC_CONVEX_URL as string); | ||
|
||
const ConvexClerkProvider = ({ children }: { children: ReactNode}) => ( | ||
<ClerkProvider publishableKey={process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY as string} appearance={{ | ||
layout: { | ||
socialButtonsVariant: 'iconButton', | ||
logoImageUrl: '/icons/auth-logo.svg', | ||
}, | ||
variables: { | ||
colorBackground: '#15171c', | ||
colorPrimary: '', | ||
colorText: 'white', | ||
colorInputBackground: '#1b1f29', | ||
colorInputText: 'white', | ||
|
||
} | ||
}}> | ||
<ConvexProviderWithClerk client={convex} useAuth={useAuth}> | ||
{ children } | ||
</ConvexProviderWithClerk> | ||
</ClerkProvider> | ||
); | ||
|
||
export default ConvexClerkProvider; |
This file was deleted.
Oops, something went wrong.