I’m building a Nextjs app with Clerk and use Azure AD of my organization with prisma and postgres as db, I want to get the details of the users in my organization when they sign up. I’ve used Clerk for Authentication. How can I get the details that is there in Azure AD when the user signs in?
SignInPage
"use client";
import { SignIn, useUser } from "@clerk/nextjs";
import Image from "next/image";
import { useRouter } from "next/navigation";
export default function SignInPage() {
const router = useRouter();
const user = useUser();
const isSignedIn = user.isSignedIn;
if (isSignedIn) {
router.replace("/onboard");
return null;
}
return (
<main className="flex h-screen w-full items-center justify-center bg-gray-100 flex-col">
<div className=" p-8 px-24 justify-center items-center flex flex-col">
<SignIn
routing="hash"
appearance={{
elements: {
footerAction: {
display: "none",
},
},
}}
/>
</div>
</main>
);
}
onboard page
import prisma from "@/lib/prisma";
import { auth, currentUser } from "@clerk/nextjs/server";
import { redirect } from "next/navigation";
export default async function Onboard() {
const userDetails = await currentUser();
const user = auth();
if (!userDetails) {
return redirect("/"); // Redirect to the homepage directly from the server
}
async function createUser(data: {
name: string;
email: string;
externalId: string;
}) {
console.log(data);
await prisma.user.upsert({
where: { externalId: userDetails?.id },
create: { ...data },
update: { ...data },
});
}
await createUser({
name: userDetails.fullName as string,
email: userDetails.primaryEmailAddress?.emailAddress as string,
externalId: userDetails.id,
});
return redirect("/Dashboard");
}
I tried NextAuth but it is very confusing, so decided to switch to clerk and how to do Azure/Entra AD based authentication on this.
New contributor
Ryomen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.