Yaki
Yaki
TTCTheo's Typesafe Cult
Created by Ben on 5/12/2024 in #questions
Weird Clerk behavior(user is null) with new API
Anyhow glad both our issues got solved 😄
21 replies
TTCTheo's Typesafe Cult
Created by Ben on 5/12/2024 in #questions
Weird Clerk behavior(user is null) with new API
Yeah I kept reading issue reports from like a couple months ago related to the new API on like SO and Github
21 replies
TTCTheo's Typesafe Cult
Created by Ben on 5/12/2024 in #questions
Weird Clerk behavior(user is null) with new API
At least the search function works most of the times
21 replies
TTCTheo's Typesafe Cult
Created by Ben on 5/12/2024 in #questions
Weird Clerk behavior(user is null) with new API
Yeah idk if I'm getting dumber but sometimes I struggle finding what I need on docs nowdays
21 replies
TTCTheo's Typesafe Cult
Created by Ben on 5/12/2024 in #questions
Weird Clerk behavior(user is null) with new API
Support from Clerk's Discord suggested the exact same article with my issue
21 replies
TTCTheo's Typesafe Cult
Created by Ben on 5/12/2024 in #questions
Weird Clerk behavior(user is null) with new API
Yeah
21 replies
TTCTheo's Typesafe Cult
Created by Ben on 5/12/2024 in #questions
Weird Clerk behavior(user is null) with new API
I also thought publicMetadata was modifiable on client side but apparently not so none of the server actions hacks I did were necessary LOL
21 replies
TTCTheo's Typesafe Cult
Created by Ben on 5/12/2024 in #questions
Weird Clerk behavior(user is null) with new API
Initially I was using metadata but then I saw "Roles and Permissions" on the dashboard and I was like yeah that makes more sense
21 replies
TTCTheo's Typesafe Cult
Created by Ben on 5/12/2024 in #questions
Weird Clerk behavior(user is null) with new API
Neat! Glad you solved your issue. Man I love realizing I was doing it all wrong with 5 minutes of reading 🤡
21 replies
TTCTheo's Typesafe Cult
Created by Ben on 5/12/2024 in #questions
Weird Clerk behavior(user is null) with new API
Woops my bad I just realized your issue is even worse since you're not even getting the user data. Mine is annoying because I'm trying to implement the Organizations feature to have roles and permissions to handle the auth but I'm gonna have to do it on the API layer it seems... Have you tried removing the auth().protect() on your middleware to check if that's the problem?
21 replies
TTCTheo's Typesafe Cult
Created by Ben on 5/12/2024 in #questions
Weird Clerk behavior(user is null) with new API
Asked earlier on the Clerk discord but no response yet. I tried downgrading to an earlier version (4.30) and it didn't work. Read on SO that dropping turbo compiler could also help but nope. Hope I get a reply soon so I can keep moving with this :sigh:
21 replies
TTCTheo's Typesafe Cult
Created by Ben on 5/12/2024 in #questions
Weird Clerk behavior(user is null) with new API
Yeah I have the same issue This is the console log output of user at the middleware
sessionId:'sess_2hAK5jvdGE1rN1H24YooVjYaQYn',
userId: 'user_2hA91TfiE6EvNZxq8FbY9dD5s5Y',
orgId: undefined,
orgRole: undefined,
orgSlug: undefined,
orgPermissions: undefined,
getToken: [Function],
has: [Function],
debug: [Function],
protect: [Function],
redirectToSignIn: [Function]
sessionId:'sess_2hAK5jvdGE1rN1H24YooVjYaQYn',
userId: 'user_2hA91TfiE6EvNZxq8FbY9dD5s5Y',
orgId: undefined,
orgRole: undefined,
orgSlug: undefined,
orgPermissions: undefined,
getToken: [Function],
has: [Function],
debug: [Function],
protect: [Function],
redirectToSignIn: [Function]
middleware.ts:
import { clerkMiddleware, createRouteMatcher } from "@clerk/nextjs/server";

const isProtectedRoute = createRouteMatcher(["/dashboard(.*)"]);

export default clerkMiddleware((auth, request) => {
const user = auth();
console.log(user);
if (isProtectedRoute(request)) auth().protect();
});

export const config = {
matcher: ["/((?!.+\\.[\\w]+$|_next).*)", "/", "/(api|trpc)(.*)"],
};
import { clerkMiddleware, createRouteMatcher } from "@clerk/nextjs/server";

const isProtectedRoute = createRouteMatcher(["/dashboard(.*)"]);

export default clerkMiddleware((auth, request) => {
const user = auth();
console.log(user);
if (isProtectedRoute(request)) auth().protect();
});

export const config = {
matcher: ["/((?!.+\\.[\\w]+$|_next).*)", "/", "/(api|trpc)(.*)"],
};
21 replies