Skip to content

Commit

Permalink
feat(web): update clerk to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminshafii committed Dec 31, 2024
1 parent 96ad268 commit 2b7dcda
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 57 deletions.
2 changes: 1 addition & 1 deletion packages/web/app/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export async function createLicenseKeyFromUserId(userId: string) {

export async function createLicenseKey() {
"use server";
const { userId } = auth();
const { userId } = await auth();
console.log("Creating license key - User authenticated:", !!userId);
if (!userId) {
return null;
Expand Down
10 changes: 6 additions & 4 deletions packages/web/app/api/anon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { auth, clerkClient } from "@clerk/nextjs/server";
// Create an anonymous user
export const createAnonymousUser = async () => {
try {
const user = await clerkClient().users.createUser({
const client = await clerkClient();
const user = await client.users.createUser({
skipPasswordRequirement: true,
skipPasswordChecks: true,
firstName: 'Anonymous',
Expand All @@ -22,7 +23,8 @@ export const createAnonymousUser = async () => {
export const updateAnonymousUserEmail = async (userId: string, newEmail: string) => {
console.log("updateAnonymousUserEmail", userId, newEmail);
try {
const user = await clerkClient().users.getUser(userId);
const client = await clerkClient();
const user = await client.users.getUser(userId);

// Check if the user has an anonymous email
const isAnonymous = user.emailAddresses.some(email =>
Expand All @@ -32,7 +34,7 @@ export const updateAnonymousUserEmail = async (userId: string, newEmail: string)

if (isAnonymous) {
// First create the new email address
await clerkClient().emailAddresses.createEmailAddress({
await client.emailAddresses.createEmailAddress({
userId: userId,
emailAddress: newEmail,
primary: true,
Expand All @@ -47,7 +49,7 @@ export const updateAnonymousUserEmail = async (userId: string, newEmail: string)
);
console.log("anonymousEmail", anonymousEmail);
if (anonymousEmail) {
await clerkClient().emailAddresses.deleteEmailAddress(anonymousEmail.id);
await client.emailAddresses.deleteEmailAddress(anonymousEmail.id);
}

console.log(`Updated email for user ${userId} to ${newEmail}`);
Expand Down
2 changes: 1 addition & 1 deletion packages/web/app/api/deployment/status/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Vercel } from "@vercel/sdk";

export async function GET() {
try {
const { userId } = auth();
const { userId } = await auth();
if (!userId) {
return new NextResponse("Unauthorized", { status: 401 });
}
Expand Down
2 changes: 1 addition & 1 deletion packages/web/app/api/deployment/update-key/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Vercel } from "@vercel/sdk";

export async function POST(request: Request) {
try {
const { userId } = auth();
const { userId } = await auth();
if (!userId) {
return new NextResponse("Unauthorized", { status: 401 });
}
Expand Down
2 changes: 1 addition & 1 deletion packages/web/app/api/redeploy/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { eq } from "drizzle-orm";

export async function POST() {
try {
const { userId } = auth();
const { userId } = await auth();
if (!userId) {
return new NextResponse("Unauthorized", { status: 401 });
}
Expand Down
2 changes: 1 addition & 1 deletion packages/web/app/claim-offer/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export async function claimTokens() {
}

// Get authenticated user
const { userId } = auth();
const { userId } = await auth();
if (!userId) {
return { error: "You must be logged in to claim tokens" };
}
Expand Down
2 changes: 1 addition & 1 deletion packages/web/app/dashboard/deployment/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function updateKeys({
generateNewLicenseKey?: boolean;
}): Promise<UpdateKeysResult> {
try {
const { userId } = auth();
const { userId } = await auth();
if (!userId) {
return { success: false, error: "Unauthorized" };
}
Expand Down
4 changes: 2 additions & 2 deletions packages/web/app/dashboard/lifetime/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function setupProject(
vercelToken: string,
openaiKey: string
): Promise<SetupProjectResult> {
const { userId } = auth();
const { userId } = await auth();
// create an api key for the user
if (!userId) {
throw new Error("User not authenticated");
Expand Down Expand Up @@ -151,7 +151,7 @@ export async function setupProject(

// Helper function to get user's Vercel deployment info
export async function getVercelDeployment() {
const { userId } = auth();
const { userId } = await auth();
if (!userId) {
throw new Error("User not authenticated");
}
Expand Down
10 changes: 9 additions & 1 deletion packages/web/app/dashboard/lifetime/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { AutomatedSetup } from "./automated-setup";
import { LegacySetup } from "./legacy-setup";
import { InfoIcon, BookOpenIcon } from "lucide-react";
import { InfoIcon, BookOpenIcon, Link, ArrowLeftIcon } from "lucide-react";
import { Button } from "@/components/ui/button";

export default function LifetimeAccessPage() {
return (
Expand Down Expand Up @@ -73,6 +74,13 @@ export default function LifetimeAccessPage() {
</div>
</div>
<AutomatedSetup />
{/* if you alread deployed you can also check out the deployment page */}
<Link href="/dashboard/deployment">
<Button>
<ArrowLeftIcon className="h-4 w-4" />
Back to Dashboard
</Button>
</Link>
</TabsContent>

<TabsContent value="legacy">
Expand Down
8 changes: 4 additions & 4 deletions packages/web/app/dashboard/pricing/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const getUrls = () => {
};

export async function createPayOnceLifetimeCheckout() {
const { userId } = auth();
const { userId } = await auth();
if (!userId) throw new Error("Not authenticated");
const metadata = {
userId,
Expand Down Expand Up @@ -58,7 +58,7 @@ export async function createPayOnceLifetimeCheckout() {
}

export async function createMonthlySubscriptionCheckout() {
const { userId } = auth();
const { userId } = await auth();
if (!userId) throw new Error("Not authenticated");

const { success, cancel } = getUrls();
Expand Down Expand Up @@ -139,14 +139,14 @@ export async function createYearlySession(userId: string) {
}

export async function createYearlySubscriptionCheckout() {
const { userId } = auth();
const { userId } = await auth();
if (!userId) throw new Error("Not authenticated");
const session = await createYearlySession(userId);
redirect(session.url!);
}

export async function createPayOnceOneYearCheckout() {
const { userId } = auth();
const { userId } = await auth();
if (!userId) throw new Error("Not authenticated");

const { success, cancel } = getUrls();
Expand Down
2 changes: 1 addition & 1 deletion packages/web/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default async function MainPage() {
redirect("/dashboard/self-hosted");
}

const { userId } = auth();
const { userId } = await auth();

const billingCycle = await getUserBillingCycle(userId);
console.log("Billing cycle:", billingCycle);
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/user-management.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { auth } from "@clerk/nextjs/server";
import { isPaidUser } from "@/app/actions";

export default async function UserManagement() {
const { userId } = auth();
const { userId } = await auth();
const isPaid = await isPaidUser(userId);

return (
Expand Down
15 changes: 8 additions & 7 deletions packages/web/lib/handleAuthorization.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { clerkClient } from "@clerk/nextjs/server";
import { clerkClient } from "@clerk/nextjs/server";
import { verifyKey } from "@unkey/api";
import { NextRequest } from "next/server";
import { checkTokenUsage } from "../drizzle/schema";
Expand All @@ -13,8 +13,8 @@ async function handleLogging(
userId: string,
isCustomer: boolean
) {
const user = await clerkClient().users.getUser(userId);
console.log("user", user.emailAddresses[0]?.emailAddress);
const authClient = await clerkClient();
const user = await authClient.users.getUser(userId);
const client = PostHogClient();
if (client) {
client.capture({
Expand All @@ -33,11 +33,12 @@ async function handleLoggingV2(
req: NextRequest,
userId: string,
) {
const user = await clerkClient.users.getUser(userId);
const client = await clerkClient();
const user = await client.users.getUser(userId);
console.log("user", user.emailAddresses[0]?.emailAddress);
const client = PostHogClient();
if (client) {
client.capture({
const posthogClient = PostHogClient();
if (posthogClient) {
posthogClient.capture({
distinctId: userId,
event: "call-api",
properties: {
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion packages/web/lib/services/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { CustomerData } from '../../app/api/webhook/types';

export async function updateClerkMetadata(data: CustomerData) {
try {
await clerkClient().users.updateUserMetadata(data.userId, {
const client = await clerkClient();
await client.users.updateUserMetadata(data.userId, {
publicMetadata: {
stripe: {
customerId: data.customerId,
Expand Down
2 changes: 1 addition & 1 deletion packages/web/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const userManagementMiddleware = () =>
return NextResponse.next();
}
if (isCheckoutApiRoute(req) || isAuthRoute(req)) {
auth().protect();
auth.protect();
}
return NextResponse.next();
});
Expand Down
2 changes: 1 addition & 1 deletion packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@ai-sdk/anthropic": "^1.0.6",
"@ai-sdk/openai": "^1.0.6",
"@browserbasehq/stagehand": "^1.5.0",
"@clerk/nextjs": "^5.7.5",
"@clerk/nextjs": "^6.9.6",
"@hookform/resolvers": "^3.9.1",
"@radix-ui/react-dialog": "^1.1.2",
"@radix-ui/react-label": "^2.1.0",
Expand Down
57 changes: 29 additions & 28 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2b7dcda

Please sign in to comment.