conniehunt
conniehunt
Explore posts from servers
TTCTheo's Typesafe Cult
Created by rovrav on 9/8/2023 in #questions
NODE_ENV exposed to the client? Is that okay?
sorry i just edited, just use process.env.NODE_ENV. it is provided out of the box by next
18 replies
TTCTheo's Typesafe Cult
Created by rovrav on 9/8/2023 in #questions
NODE_ENV exposed to the client? Is that okay?
const localURL = process.env.NEXT_PUBLIC_LOCAL_URL;
const prodURL = process.env.NEXT_PUBLIC_VERCEL_URL;

export const baseURL =
process.env.NODE_ENV === 'development' ? localURL : prodURL;
const localURL = process.env.NEXT_PUBLIC_LOCAL_URL;
const prodURL = process.env.NEXT_PUBLIC_VERCEL_URL;

export const baseURL =
process.env.NODE_ENV === 'development' ? localURL : prodURL;
Is this what you need?
18 replies
TTCTheo's Typesafe Cult
Created by conniehunt on 5/27/2023 in #questions
NextJS(13) API call cache MISS
🙏🙏🙏
10 replies
TTCTheo's Typesafe Cult
Created by conniehunt on 5/27/2023 in #questions
NextJS(13) API call cache MISS
10 replies
TTCTheo's Typesafe Cult
Created by conniehunt on 5/27/2023 in #questions
NextJS(13) API call cache MISS
like this?
import { auth, clerkClient } from '@clerk/nextjs/server';
import { NextRequest, NextResponse } from 'next/server';

export async function GET(req: NextRequest) {
console.log('✅ Received request to add credits');

const headers = new Headers({
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE',
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
'Access-Control-Allow-Credentials': 'true',
});

const { userId } = auth();
console.log('Got userId:', userId);

if (typeof userId !== 'string') return;

const user = await clerkClient.users.getUser(userId);
console.log('Got user:', user);
const credits: any = user.publicMetadata.credits;

try {
const updatedUser = await clerkClient.users.updateUserMetadata(userId, {
publicMetadata: {
credits: credits + 100,
},
});
console.log('added credits');
return NextResponse.json({ success: true, user: updatedUser });
} catch (err) {
console.error('error deducting credits', err);
}

return new Response(req.body, {
headers: headers,
});
}
import { auth, clerkClient } from '@clerk/nextjs/server';
import { NextRequest, NextResponse } from 'next/server';

export async function GET(req: NextRequest) {
console.log('✅ Received request to add credits');

const headers = new Headers({
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE',
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
'Access-Control-Allow-Credentials': 'true',
});

const { userId } = auth();
console.log('Got userId:', userId);

if (typeof userId !== 'string') return;

const user = await clerkClient.users.getUser(userId);
console.log('Got user:', user);
const credits: any = user.publicMetadata.credits;

try {
const updatedUser = await clerkClient.users.updateUserMetadata(userId, {
publicMetadata: {
credits: credits + 100,
},
});
console.log('added credits');
return NextResponse.json({ success: true, user: updatedUser });
} catch (err) {
console.error('error deducting credits', err);
}

return new Response(req.body, {
headers: headers,
});
}
10 replies
TTCTheo's Typesafe Cult
Created by conniehunt on 5/27/2023 in #questions
NextJS(13) API call cache MISS
i dont quite understand, Am n00b
10 replies