Burhan
Burhan
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Burhan on 3/2/2024 in #questions
Public and Private procedures Not working with Clerk and Prisma
Anyone got an idea?
18 replies
TTCTheo's Typesafe Cult
Created by Burhan on 3/2/2024 in #questions
Public and Private procedures Not working with Clerk and Prisma
@Matvey
18 replies
TTCTheo's Typesafe Cult
Created by Burhan on 3/2/2024 in #questions
Public and Private procedures Not working with Clerk and Prisma
18 replies
TTCTheo's Typesafe Cult
Created by Burhan on 3/2/2024 in #questions
Public and Private procedures Not working with Clerk and Prisma
I followed this documentation
18 replies
TTCTheo's Typesafe Cult
Created by Burhan on 3/2/2024 in #questions
Public and Private procedures Not working with Clerk and Prisma
18 replies
TTCTheo's Typesafe Cult
Created by Burhan on 3/2/2024 in #questions
Public and Private procedures Not working with Clerk and Prisma
Still getting the unexpected token error
18 replies
TTCTheo's Typesafe Cult
Created by Burhan on 3/2/2024 in #questions
Public and Private procedures Not working with Clerk and Prisma
This still isnt working tho
18 replies
TTCTheo's Typesafe Cult
Created by Burhan on 3/2/2024 in #questions
Public and Private procedures Not working with Clerk and Prisma
Like this? @Matvey
18 replies
TTCTheo's Typesafe Cult
Created by Burhan on 3/2/2024 in #questions
Public and Private procedures Not working with Clerk and Prisma
import { authMiddleware } from "@clerk/nextjs";

export default authMiddleware({
// Routes that can be accessed while signed out
publicRoutes: ['/anyone-can-visit-this-route', '/api/trpc/'],
// Routes that can always be accessed, and have
// no authentication information
ignoredRoutes: ['/no-auth-in-this-route'],
});

export const config = {
// Protects all routes, including api/trpc.
// See https://clerk.com/docs/references/nextjs/auth-middleware
// for more information about configuring your Middleware
// matcher: ["/((?!.+\\.[\\w]+$|_next).*)", "/", "/(api|trpc)(.*)"],
};
import { authMiddleware } from "@clerk/nextjs";

export default authMiddleware({
// Routes that can be accessed while signed out
publicRoutes: ['/anyone-can-visit-this-route', '/api/trpc/'],
// Routes that can always be accessed, and have
// no authentication information
ignoredRoutes: ['/no-auth-in-this-route'],
});

export const config = {
// Protects all routes, including api/trpc.
// See https://clerk.com/docs/references/nextjs/auth-middleware
// for more information about configuring your Middleware
// matcher: ["/((?!.+\\.[\\w]+$|_next).*)", "/", "/(api|trpc)(.*)"],
};
18 replies
TTCTheo's Typesafe Cult
Created by Burhan on 3/2/2024 in #questions
Public and Private procedures Not working with Clerk and Prisma
This is where the error is arising from
18 replies
TTCTheo's Typesafe Cult
Created by Burhan on 3/2/2024 in #questions
Public and Private procedures Not working with Clerk and Prisma
import { TRPCError, type inferAsyncReturnType, initTRPC } from "@trpc/server";
import { type CreateNextContextOptions } from "@trpc/server/adapters/next";
import { getAuth, type SignedInAuthObject, type SignedOutAuthObject } from '@clerk/nextjs/server';
import superjson from "superjson";
import { ZodError } from "zod";

import { prisma } from "~/server/prisma";

type CreateContextOptions = Record<string, never>;


interface AuthContext {
auth: SignedInAuthObject | SignedOutAuthObject;
}

export const createContextInner = async ({ auth }: AuthContext ) => {
return {
auth,
}
}


// const createInnerTRPCContext = (_opts: CreateContextOptions) => {
// return {
// prisma,
// };
// };

// export const createTRPCContext = (opts: CreateNextContextOptions) => {
// return {
// ...createInnerTRPCContext({}),
// req: opts.req,
// };
// };

export const createContext = async (opts: CreateNextContextOptions) => {
return await createContextInner({ auth: getAuth(opts.req) })
}


const t = initTRPC.context<Context>().create({
transformer: superjson,
errorFormatter({ shape }) {
return shape
}
})

export const createTRPCRouter = t.router;
export type Context = inferAsyncReturnType<typeof createContext>;

export const publicProcedure = t.procedure;


const isAuthed = t.middleware(({ next, ctx }) => {
if (!ctx.auth.userId) {
throw new TRPCError({ code: 'UNAUTHORIZED' })
}
return next({
ctx: {
auth: ctx.auth,
},
})
})

// export this procedure to be used anywhere in your application
export const protectedProcedure = t.procedure.use(isAuthed)

export const mergeRouters = t.mergeRouters;
import { TRPCError, type inferAsyncReturnType, initTRPC } from "@trpc/server";
import { type CreateNextContextOptions } from "@trpc/server/adapters/next";
import { getAuth, type SignedInAuthObject, type SignedOutAuthObject } from '@clerk/nextjs/server';
import superjson from "superjson";
import { ZodError } from "zod";

import { prisma } from "~/server/prisma";

type CreateContextOptions = Record<string, never>;


interface AuthContext {
auth: SignedInAuthObject | SignedOutAuthObject;
}

export const createContextInner = async ({ auth }: AuthContext ) => {
return {
auth,
}
}


// const createInnerTRPCContext = (_opts: CreateContextOptions) => {
// return {
// prisma,
// };
// };

// export const createTRPCContext = (opts: CreateNextContextOptions) => {
// return {
// ...createInnerTRPCContext({}),
// req: opts.req,
// };
// };

export const createContext = async (opts: CreateNextContextOptions) => {
return await createContextInner({ auth: getAuth(opts.req) })
}


const t = initTRPC.context<Context>().create({
transformer: superjson,
errorFormatter({ shape }) {
return shape
}
})

export const createTRPCRouter = t.router;
export type Context = inferAsyncReturnType<typeof createContext>;

export const publicProcedure = t.procedure;


const isAuthed = t.middleware(({ next, ctx }) => {
if (!ctx.auth.userId) {
throw new TRPCError({ code: 'UNAUTHORIZED' })
}
return next({
ctx: {
auth: ctx.auth,
},
})
})

// export this procedure to be used anywhere in your application
export const protectedProcedure = t.procedure.use(isAuthed)

export const mergeRouters = t.mergeRouters;
18 replies
TTCTheo's Typesafe Cult
Created by Burhan on 3/2/2024 in #questions
Public and Private procedures Not working with Clerk and Prisma
No description
18 replies
TTCTheo's Typesafe Cult
Created by Burhan on 12/8/2023 in #questions
Need help to programmatically trigger `next export` script to get static pages.
I have already tested it by maually running the next export script and everything works perfectly fine My requirement is to somehow trigger the next export and get the static pages on the push of a button
5 replies
TTCTheo's Typesafe Cult
Created by Burhan on 12/8/2023 in #questions
Need help to programmatically trigger `next export` script to get static pages.
Api Was Hit::
Export process started
API resolved without sending a response for /api/export, this may result in stalled requests.
Export process output:
> @examples/[email protected] export E:\Github-clones\Codeless-Cms\Codeless-Cms
> next build && next export

info - Linting and checking validity of types...
info - Creating an optimized production build...
 ELIFECYCLE  Command failed with exit code 1.
Api Was Hit::
Export process started
API resolved without sending a response for /api/export, this may result in stalled requests.
Export process output:
> @examples/[email protected] export E:\Github-clones\Codeless-Cms\Codeless-Cms
> next build && next export

info - Linting and checking validity of types...
info - Creating an optimized production build...
 ELIFECYCLE  Command failed with exit code 1.
5 replies
TTCTheo's Typesafe Cult
Created by Burhan on 12/8/2023 in #questions
Need help to programmatically trigger `next export` script to get static pages.
This below is the error that I am getting
5 replies
TTCTheo's Typesafe Cult
Created by Burhan on 12/8/2023 in #questions
Need help to programmatically trigger `next export` script to get static pages.
/api/export.ts
import { spawn } from 'child_process';
import { NextApiRequest, NextApiResponse } from 'next';

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
console.log("Api Was Hit::")
try {
console.log('Export process started');
// Spawn a child process to run the `next export` command
const exportProcess = spawn(/^win/.test(process.platform) ? 'pnpm.cmd' : 'pnpm', ['run', 'export'], { timeout: 240000 });

// Collect the output of the export process
let exportProcessOutput = '';
exportProcess.stdout.on('data', (data) => {
exportProcessOutput += data.toString();
});

// Listen for any errors that occur during the export process
exportProcess.on('error', (err) => {
console.error(err);
res.status(500).send('Error occurred during export process');
});

// Listen for when the export process completes
exportProcess.on('close', (code) => {
if (code !== 0) {
console.error('Export process output:', exportProcessOutput);
console.error(`Export process exited with code ${code}`);
res.status(500).send('Export process failed');
} else {
console.log('Export process completed successfully');
res.status(200).send('Export process completed successfully');
}
});
} catch (error) {
console.error(error);
res.status(500).send('An error occurred');
}
}
import { spawn } from 'child_process';
import { NextApiRequest, NextApiResponse } from 'next';

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
console.log("Api Was Hit::")
try {
console.log('Export process started');
// Spawn a child process to run the `next export` command
const exportProcess = spawn(/^win/.test(process.platform) ? 'pnpm.cmd' : 'pnpm', ['run', 'export'], { timeout: 240000 });

// Collect the output of the export process
let exportProcessOutput = '';
exportProcess.stdout.on('data', (data) => {
exportProcessOutput += data.toString();
});

// Listen for any errors that occur during the export process
exportProcess.on('error', (err) => {
console.error(err);
res.status(500).send('Error occurred during export process');
});

// Listen for when the export process completes
exportProcess.on('close', (code) => {
if (code !== 0) {
console.error('Export process output:', exportProcessOutput);
console.error(`Export process exited with code ${code}`);
res.status(500).send('Export process failed');
} else {
console.log('Export process completed successfully');
res.status(200).send('Export process completed successfully');
}
});
} catch (error) {
console.error(error);
res.status(500).send('An error occurred');
}
}
5 replies