fix(auth): restore keycloak sign-in for NodePort access
Trust external host for Auth.js, provide missing frontend auth env/secrets, and submit a proper CSRF-backed sign-in POST so browser login reaches Keycloak reliably.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, Suspense } from 'react';
|
||||
import { signIn, signOut, useSession } from 'next-auth/react';
|
||||
import { signOut, useSession } from 'next-auth/react';
|
||||
import { useRouter, useSearchParams } from 'next/navigation';
|
||||
import { Card, CardHeader, CardTitle, CardContent, CardFooter } from '@/components/ui/card';
|
||||
import { Button } from '@/components/ui/button';
|
||||
@@ -18,8 +18,33 @@ function LoginContent() {
|
||||
}
|
||||
}, [status, router]);
|
||||
|
||||
const handleSignIn = () => {
|
||||
signIn('keycloak', { callbackUrl: '/dashboard' });
|
||||
const handleSignIn = async () => {
|
||||
const csrfResponse = await fetch('/api/auth/csrf');
|
||||
const csrfPayload = await csrfResponse.json() as { csrfToken?: string };
|
||||
|
||||
if (!csrfPayload.csrfToken) {
|
||||
window.location.href = '/api/auth/signin?callbackUrl=%2Fdashboard';
|
||||
return;
|
||||
}
|
||||
|
||||
const form = document.createElement('form');
|
||||
form.method = 'POST';
|
||||
form.action = '/api/auth/signin/keycloak';
|
||||
|
||||
const csrfInput = document.createElement('input');
|
||||
csrfInput.type = 'hidden';
|
||||
csrfInput.name = 'csrfToken';
|
||||
csrfInput.value = csrfPayload.csrfToken;
|
||||
form.appendChild(csrfInput);
|
||||
|
||||
const callbackInput = document.createElement('input');
|
||||
callbackInput.type = 'hidden';
|
||||
callbackInput.name = 'callbackUrl';
|
||||
callbackInput.value = `${window.location.origin}/dashboard`;
|
||||
form.appendChild(callbackInput);
|
||||
|
||||
document.body.appendChild(form);
|
||||
form.submit();
|
||||
};
|
||||
|
||||
const handleSwitchAccount = () => {
|
||||
|
||||
Reference in New Issue
Block a user