nimeshvaghasiya
nimeshvaghasiya
Explore posts from servers
TTCTheo's Typesafe Cult
Created by nimeshvaghasiya on 1/16/2023 in #questions
error - ReferenceError: Cannot access 'createTRPCRouter' before initialization
20 replies
TTCTheo's Typesafe Cult
Created by nimeshvaghasiya on 1/16/2023 in #questions
error - ReferenceError: Cannot access 'createTRPCRouter' before initialization
I have created latest create t3 app: https://github.com/nimeshvaghasiya/t3routererror Steps to reproduce error: - Clone above repository, do npm install then npm run dev - Click on "Roles" - Click on "Sign in" button : throws error - If you comment out signin callback, there will be no error. @JacobMGEvans @0𝙚𝙪𝙚 ✓ I would like to open an issue to t3app github repo, if someone can confirm this is a real issue.
20 replies
TTCTheo's Typesafe Cult
Created by nimeshvaghasiya on 1/16/2023 in #questions
error - ReferenceError: Cannot access 'createTRPCRouter' before initialization
I have found exact issue which is causing an error. you can't use "createTRPCContext" inside next auth signIn callback even if you wrap auth options to access NextApiRequest and NextApiResponse, I need to wrap it because i need some cookie values. Using "createInnerTRPCContext" does fix an error:
const ctx = await createInnerTRPCContext({ session: null });
const caller = appRouter.createCaller(ctx);
const ctx = await createInnerTRPCContext({ session: null });
const caller = appRouter.createCaller(ctx);
Code (signIn callback lines produce unusual error as mentioned in title):
export const authOptions = (req: NextApiRequest | undefined = undefined, res: NextApiResponse | undefined = undefined): NextAuthOptions => {
return {
callbacks: {
async signIn({ user, account, profile, email, credentials }) {
const ctx = await createTRPCContext({ req, res });
const caller = appRouter.createCaller(ctx);
caller.role.getAllPermissions({...})
...
}
}
...
}
};

// export default NextAuth(authOptions);
export default (req: NextApiRequest, res: NextApiResponse) => {
return NextAuth(req, res, authOptions(req, res))
}
export const authOptions = (req: NextApiRequest | undefined = undefined, res: NextApiResponse | undefined = undefined): NextAuthOptions => {
return {
callbacks: {
async signIn({ user, account, profile, email, credentials }) {
const ctx = await createTRPCContext({ req, res });
const caller = appRouter.createCaller(ctx);
caller.role.getAllPermissions({...})
...
}
}
...
}
};

// export default NextAuth(authOptions);
export default (req: NextApiRequest, res: NextApiResponse) => {
return NextAuth(req, res, authOptions(req, res))
}
@0𝙚𝙪𝙚 ✓ @JacobMGEvans Do you think using "createTRPCContext" anywhere should not cause any issue?
20 replies
TTCTheo's Typesafe Cult
Created by nimeshvaghasiya on 1/16/2023 in #questions
error - ReferenceError: Cannot access 'createTRPCRouter' before initialization
I have look into https://github.com/trpc/trpc/issues/3081 trpc repo. issue but coudn't figure out exact issue. It returns me 500 error with text/html response. I'm signing in using nextauth discord/google provider, and redirecting user to callbackUrl (dashboard), then calling some trpc routes to get permissioned navigation menu items. but trpc throws 500 with html text response.
20 replies
TTCTheo's Typesafe Cult
Created by nimeshvaghasiya on 11/10/2022 in #questions
Next 13 - App Directory feature and tRPC
@Paxilius I'm waiting for same - async components. https://beta.nextjs.org/docs/app-directory-roadmap arround 40% work is in progress for app directory!
15 replies
TTCTheo's Typesafe Cult
Created by nimeshvaghasiya on 12/13/2022 in #questions
Should you share zod schema from server side to client side?
I have search 'zod schema' and got stoyko's comment here https://discord.com/channels/966627436387266600/966627439390380064/1050343129766703104, so I thought, better to mention stoyko. my bad that I have only mentioned him without comment.
9 replies
TTCTheo's Typesafe Cult
Created by nimeshvaghasiya on 12/13/2022 in #questions
Should you share zod schema from server side to client side?
@stoyko
9 replies
TTCTheo's Typesafe Cult
Created by Froxx on 11/2/2022 in #questions
Getting no session from useSession() with NextAuth
@asheesh my bad!
25 replies
TTCTheo's Typesafe Cult
Created by Froxx on 11/2/2022 in #questions
Getting no session from useSession() with NextAuth
@create-t3-maintainer @Froxx removing session callback(as per above comment) and set session strategy: 'jwt' is working for both credential provider and discord provider. what is the reason behind this? make below change to session callback does works for me: session({ session, user }) { if (session.user **&& user**) { session.user.id = user.id; } return session; },
25 replies