quiet-intern-84955
02/13/2022, 9:22 PMexport const getUserFromContext = async ({ prisma, req }: Pick<Context, "prisma" | "req">) => {
try {
const { data: session } = await oryApiClient.toSession(undefined, req.headers.cookie);
if (!session) {
return null;
}
const user = await prisma.user.findUnique({ where: { id: session.identity.id }, include: { roles: true } });
return user;
} catch (error) {
return null;
}
};
Works completely fine locally, but since my backend is hosted on a different domain than my Next.js app I guess the cookies are undefined (correct me if I’m wrong) and it fails. Is there no way around this other than having the backend on the same domain or am I being stupid? 😄stale-queen-97584
02/13/2022, 10:04 PMdamp-sunset-69236
02/14/2022, 5:34 AM<http://frontend.example.com|frontend.example.com>
<http://kratos.example.com|kratos.example.com>
<http://backend.example.com|backend.example.com>
In that case you can have everything work fine. You can check
• Configuring Cookies
• Advanced Base URL, CSRF & Session Cookie Settings
You can add CNAME records for the backend hosted elsewhere to make it work. As another option you can setup your ingress to proxy traffic from another domain. The example of different domains is below
<http://frontend.example.com|frontend.example.com>
<http://backend.different-domain.com|backend.different-domain.com>
quiet-intern-84955
02/14/2022, 10:29 AMAuthorization
header instead of relying on the backend being on the same domain 🤔quiet-intern-84955
02/14/2022, 10:29 AM