YoPassItY
Convex Community3mo ago
7 replies
YoPassIt

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>
  );
}
Integrate WorkOS AuthKit authentication with Convex
Convex & WorkOS AuthKit | Convex Developer Hub
Was this page helpful?