use utils for clearing cookies

This commit is contained in:
Ishaan Jaff 2025-03-03 14:59:26 -08:00
parent 2ea7b975c2
commit 03aa404d4f
2 changed files with 8 additions and 12 deletions

View file

@ -20,14 +20,7 @@ import {
} from "@/components/networking";
import { jwtDecode } from "jwt-decode";
import { Form, Button as Button2, message } from "antd";
function getCookie(name: string) {
console.log("COOKIES", document.cookie)
const cookieValue = document.cookie
.split('; ')
.find(row => row.startsWith(name + '='));
return cookieValue ? cookieValue.split('=')[1] : null;
}
import { getCookie } from "@/utils/cookieUtils";
export default function Onboarding() {
const [form] = Form.useForm();

View file

@ -21,6 +21,7 @@ import { useSearchParams, useRouter } from "next/navigation";
import { Team } from "./key_team_helpers/key_list";
import { jwtDecode } from "jwt-decode";
import { Typography } from "antd";
import { clearTokenCookies } from "@/utils/cookieUtils";
const isLocal = process.env.NODE_ENV === "development";
if (isLocal != true) {
console.log = function() {};
@ -295,14 +296,15 @@ const UserDashboard: React.FC<UserDashboardProps> = ({
if (userID == null || token == null) {
// user is not logged in as yet
console.log("All cookies before redirect:", document.cookie);
// Clear token cookies using the utility function
clearTokenCookies();
const url = proxyBaseUrl
? `${proxyBaseUrl}/sso/key/generate`
: `/sso/key/generate`;
// clear cookie called "token" since user will be logging in again
document.cookie = "token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
console.log("Full URL:", url);
window.location.href = url;
@ -326,6 +328,7 @@ const UserDashboard: React.FC<UserDashboardProps> = ({
}
console.log("inside user dashboard, selected team", selectedTeam);
console.log("All cookies after redirect:", document.cookie);
return (
<div className="w-full mx-4 h-[75vh]">
<Grid numItems={1} className="gap-2 p-8 w-full mt-2">