Skip to content

Commit

Permalink
fix: get url
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminshafii committed Dec 6, 2024
1 parent d70985c commit 120b303
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
9 changes: 5 additions & 4 deletions web/app/api/top-up/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { getToken, handleAuthorizationV2 } from "@/lib/handleAuthorization";
import { createAnonymousUser } from "../anon";
import { createLicenseKeyFromUserId } from "@/app/actions";
import { createEmptyUserUsage } from "@/drizzle/schema";
import { config, getTargetUrl, PRICES } from "@/srm.config";
import { getURL } from "@/app/dashboard/pricing/actions";

import { config, PRICES } from "@/srm.config";
import { getUrl } from "@/lib/getUrl";
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!, {
apiVersion: "2024-06-20",
});
Expand Down Expand Up @@ -47,7 +47,8 @@ export async function POST(req: NextRequest) {
);
}

const baseUrl = getURL();
const baseUrl = getUrl();
console.log("baseUrl", baseUrl);

const session = await stripe.checkout.sessions.create({
payment_method_types: ["card"],
Expand Down
15 changes: 3 additions & 12 deletions web/app/dashboard/pricing/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,16 @@ import { auth } from "@clerk/nextjs/server";
import { redirect } from "next/navigation";
import Stripe from "stripe";
import { PRODUCTS, PRICES } from "../../../srm.config";
import { getUrl } from "@/lib/getUrl";

const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!, {
apiVersion: "2024-06-20",
});

export const getURL = () => {
let url =
process?.env?.NEXT_PUBLIC_SITE_URL ?? // Set this to your site URL in production env.
process?.env?.NEXT_PUBLIC_VERCEL_URL ?? // Automatically set by Vercel.
"http://localhost:3000/";
// Make sure to include `https://` when not localhost.
url = url.startsWith("http") ? url : `https://${url}`;
// Make sure to include a trailing `/`.
url = url.endsWith("/") ? url : `${url}/`;
return url;
};

// Helper to get URLs
const getUrls = () => {
const origin = getURL();
const origin = getUrl();
return {
success: `${origin}/dashboard/subscribers`,
cancel: `${origin}/dashboard`,
Expand Down
11 changes: 11 additions & 0 deletions web/lib/getUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const getUrl = () => {
let url =
process?.env?.NEXT_PUBLIC_SITE_URL ?? // Set this to your site URL in production env.
process?.env?.NEXT_PUBLIC_VERCEL_URL ?? // Automatically set by Vercel.
"http://localhost:3000/";
// Make sure to include `https://` when not localhost.
url = url.startsWith("http") ? url : `https://${url}`;
// Make sure to include a trailing `/`.
url = url.endsWith("/") ? url : `${url}/`;
return url;
};
2 changes: 1 addition & 1 deletion web/lib/handleAuthorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function handleLogging(
userId: string,
isCustomer: boolean
) {
const user = await clerkClient.users.getUser(userId);
const user = await clerkClient().users.getUser(userId);
console.log("user", user.emailAddresses[0]?.emailAddress);
const client = PostHogClient();
if (client) {
Expand Down
2 changes: 1 addition & 1 deletion web/lib/services/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CustomerData } from '../../app/api/webhook/types';

export async function updateClerkMetadata(data: CustomerData) {
try {
await clerkClient.users.updateUserMetadata(data.userId, {
await clerkClient().users.updateUserMetadata(data.userId, {
publicMetadata: {
stripe: {
customerId: data.customerId,
Expand Down

0 comments on commit 120b303

Please sign in to comment.