YoPassIt
YoPassIt3w ago

content within <Unauthenticated /> display regardless of user status

I followed the WorkOS authentication guide for Next.js at https://docs.convex.dev/auth/authkit/ and after signing up with a google account, and the user object being present from workos' useAuth(), it still only displays the content from <Unauthenticated /> and not <Authenticated />.
"use client";

import { Authenticated, Unauthenticated } from "convex/react";
import { useAuth } from "@workos-inc/authkit-nextjs/components";
import Link from "next/link";

export default function Home() {
const { user, signOut } = useAuth();

return (
<div className="p-4">
<div className="flex justify-between items-center mb-4">
<h1>Convex + AuthKit</h1>
<div className="flex gap-2">
{user ? (
<button onClick={() => signOut()}>Sign out</button>
) : (
<>
<Link href="/sign-in">
<button>Sign in</button>
</Link>
<Link href="/sign-up">
<button>Sign up</button>
</Link>
</>
)}
</div>
</div>
<Authenticated>
<p>You are authenticated {user?.firstName}.</p>
</Authenticated>
<Unauthenticated>
<p>Please sign in to view data</p>
</Unauthenticated>
</div>
);
}
"use client";

import { Authenticated, Unauthenticated } from "convex/react";
import { useAuth } from "@workos-inc/authkit-nextjs/components";
import Link from "next/link";

export default function Home() {
const { user, signOut } = useAuth();

return (
<div className="p-4">
<div className="flex justify-between items-center mb-4">
<h1>Convex + AuthKit</h1>
<div className="flex gap-2">
{user ? (
<button onClick={() => signOut()}>Sign out</button>
) : (
<>
<Link href="/sign-in">
<button>Sign in</button>
</Link>
<Link href="/sign-up">
<button>Sign up</button>
</Link>
</>
)}
</div>
</div>
<Authenticated>
<p>You are authenticated {user?.firstName}.</p>
</Authenticated>
<Unauthenticated>
<p>Please sign in to view data</p>
</Unauthenticated>
</div>
);
}
Convex & WorkOS AuthKit | Convex Developer Hub
Integrate WorkOS AuthKit authentication with Convex
5 Replies
Convex Bot
Convex Bot3w ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
YoPassIt
YoPassItOP3w ago
isAuthenticated from useConvexAuth() is false, while the user object from workos' useAuth() is populated and logged in.
erquhart
erquhart3w ago
Can you share your convex/auth.config.ts
YoPassIt
YoPassItOP3w ago
const clientId = process.env.WORKOS_CLIENT_ID;

const authConfig = {
providers: [
{
type: 'customJwt',
issuer: `https://api.workos.com/`,
algorithm: 'RS256',
applicationID: clientId,
jwks: `https://api.workos.com/sso/jwks/${clientId}`,
},
{
type: 'customJwt',
issuer: `https://api.workos.com/user_management/${clientId}`,
algorithm: 'RS256',
jwks: `https://api.workos.com/sso/jwks/${clientId}`,
applicationID: clientId,
},
],
};

export default authConfig;
const clientId = process.env.WORKOS_CLIENT_ID;

const authConfig = {
providers: [
{
type: 'customJwt',
issuer: `https://api.workos.com/`,
algorithm: 'RS256',
applicationID: clientId,
jwks: `https://api.workos.com/sso/jwks/${clientId}`,
},
{
type: 'customJwt',
issuer: `https://api.workos.com/user_management/${clientId}`,
algorithm: 'RS256',
jwks: `https://api.workos.com/sso/jwks/${clientId}`,
applicationID: clientId,
},
],
};

export default authConfig;
I switched to Clerk now so this isn't a problem anymore for me, but just following the guide for Next.js on the Authkit seems to fail. Should be worth looking into. Its also not because of it being Next.js 16, only difference there is that middleware.ts is now called proxy.ts but its esseentially the same.
erquhart
erquhart2w ago
Needed to drop the applicationID from that second entry, docs need to be updated for this

Did you find this page helpful?