Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 13 additions & 24 deletions src/app/(auth)/actions.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
"use server";

import { cookies } from "next/headers";
import { redirect } from "next/navigation";

export async function logout() {
const cookieStore = cookies();
const accessToken = cookieStore.get("access_token")?.value;

if (!accessToken) {
return redirect("/login");
}

cookieStore.set("access_token", "", {
path: "/",
maxAge: 0,
});
cookieStore.set("user", "", { path: "/", maxAge: 0 });
cookieStore.set("refresh_token", "", {
path: "/api/auth/refresh",
maxAge: 0,
});
const keycloakLogoutUrl = `${process.env.NEXT_PUBLIC_KEYCLOAK_LOGOUT_URL || "http://localhost:8084/realms/kong/protocol/openid-connect/logout"}?client_id=kong-oidc&post_logout_redirect_uri=${process.env.NEXT_PUBLIC_KEYCLOAK_REDIRECT_URI || "http://localhost:3000/login"}`;
return redirect(keycloakLogoutUrl);
export function logout() {
// Clear client-side cookies
document.cookie = "access_token=; path=/; max-age=0; Secure; SameSite=Lax";
document.cookie = "user=; path=/; max-age=0; Secure; SameSite=Lax";
document.cookie =
"refresh_token=; path=/api/auth/refresh; max-age=0; Secure; SameSite=Lax";

// Redirect to Keycloak logout endpoint
const logoutUrl = process.env.NEXT_PUBLIC_KEYCLOAK_LOGOUT_URL!;
const redirectUri = process.env.NEXT_PUBLIC_KEYCLOAK_REDIRECT_URI!.trim();

const fullLogoutUrl = `${logoutUrl}?client_id=kong-oidc&post_logout_redirect_uri=${encodeURIComponent(redirectUri)}`;
window.location.href = fullLogoutUrl;
}
2 changes: 1 addition & 1 deletion src/app/(auth)/login/GoogleSignInButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function GoogleSignInButton() {
<a
href={
process.env.NEXT_PUBLIC_GOOGLE_AUTH_URL ||
"http://localhost:8080/oauth2/authorization/google"
"https://gotogetheruom.duckdns.org/oauth2/authorization/keycloak"
}
className="flex w-full items-center gap-2"
>
Expand Down
2 changes: 1 addition & 1 deletion src/app/(auth)/login/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export async function login(

cookieStore.set("access_token", accessToken, {
path: "/",
httpOnly: true,
httpOnly: false,
secure: process.env.NODE_ENV === "production",
maxAge: 3600, // Or use expiresIn from backend response if available and preferred
});
Expand Down
Loading