mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-04-03 17:38:47 +02:00
nit: naming
This commit is contained in:
parent
100dd0ad53
commit
fe5654fd1e
@ -11,7 +11,7 @@ import { pageType } from "@/app/chat/sessionSidebar/types";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { ChatBanner } from "@/app/chat/ChatBanner";
|
||||
import LogoType from "../header/LogoType";
|
||||
import { NotificationCard } from "./Notification";
|
||||
import { Notifications } from "./Notifications";
|
||||
import { useUser } from "../user/UserProvider";
|
||||
|
||||
export default function FunctionalHeader({
|
||||
@ -110,7 +110,7 @@ export default function FunctionalHeader({
|
||||
</div>
|
||||
)}
|
||||
|
||||
<NotificationCard />
|
||||
<Notifications />
|
||||
<div className="mobile:hidden flex my-auto">
|
||||
<UserDropdown user={user} />
|
||||
</div>
|
||||
|
@ -12,7 +12,7 @@ import { useAssistants } from "../context/AssisantsContext";
|
||||
import { useUser } from "../user/UserProvider";
|
||||
import { Bell } from "@phosphor-icons/react";
|
||||
|
||||
export const NotificationCard = () => {
|
||||
export const Notifications = () => {
|
||||
const [showDropdown, setShowDropdown] = useState(false);
|
||||
const {
|
||||
data: notifications,
|
@ -1,166 +0,0 @@
|
||||
import { cookies } from "next/headers";
|
||||
import { User } from "./types";
|
||||
import { buildUrl } from "./utilsSS";
|
||||
import { ReadonlyRequestCookies } from "next/dist/server/web/spec-extension/adapters/request-cookies";
|
||||
import { AuthType } from "./constants";
|
||||
|
||||
export interface AuthTypeMetadata {
|
||||
authType: AuthType;
|
||||
autoRedirect: boolean;
|
||||
requiresVerification: boolean;
|
||||
}
|
||||
|
||||
export const getAuthTypeMetadataSS = async (): Promise<AuthTypeMetadata> => {
|
||||
const res = await fetch(buildUrl("/auth/type"));
|
||||
if (!res.ok) {
|
||||
throw new Error("Failed to fetch data");
|
||||
}
|
||||
|
||||
const data: { auth_type: string; requires_verification: boolean } =
|
||||
await res.json();
|
||||
const authType = data.auth_type as AuthType;
|
||||
|
||||
// for SAML / OIDC, we auto-redirect the user to the IdP when the user visits
|
||||
// Danswer in an un-authenticated state
|
||||
if (authType === "oidc" || authType === "saml") {
|
||||
return {
|
||||
authType,
|
||||
autoRedirect: true,
|
||||
requiresVerification: data.requires_verification,
|
||||
};
|
||||
}
|
||||
return {
|
||||
authType,
|
||||
autoRedirect: false,
|
||||
requiresVerification: data.requires_verification,
|
||||
};
|
||||
};
|
||||
|
||||
export const getAuthDisabledSS = async (): Promise<boolean> => {
|
||||
return (await getAuthTypeMetadataSS()).authType === "disabled";
|
||||
};
|
||||
|
||||
const getOIDCAuthUrlSS = async (nextUrl: string | null): Promise<string> => {
|
||||
const res = await fetch(
|
||||
buildUrl(
|
||||
`/auth/oidc/authorize${nextUrl ? `?next=${encodeURIComponent(nextUrl)}` : ""}`
|
||||
)
|
||||
);
|
||||
if (!res.ok) {
|
||||
throw new Error("Failed to fetch data");
|
||||
}
|
||||
|
||||
const data: { authorization_url: string } = await res.json();
|
||||
return data.authorization_url;
|
||||
};
|
||||
|
||||
const getGoogleOAuthUrlSS = async (): Promise<string> => {
|
||||
const res = await fetch(buildUrl(`/auth/oauth/authorize`));
|
||||
if (!res.ok) {
|
||||
throw new Error("Failed to fetch data");
|
||||
}
|
||||
|
||||
const data: { authorization_url: string } = await res.json();
|
||||
return data.authorization_url;
|
||||
};
|
||||
|
||||
const getSAMLAuthUrlSS = async (): Promise<string> => {
|
||||
const res = await fetch(buildUrl("/auth/saml/authorize"));
|
||||
if (!res.ok) {
|
||||
throw new Error("Failed to fetch data");
|
||||
}
|
||||
|
||||
const data: { authorization_url: string } = await res.json();
|
||||
return data.authorization_url;
|
||||
};
|
||||
|
||||
export const getAuthUrlSS = async (
|
||||
authType: AuthType,
|
||||
nextUrl: string | null
|
||||
): Promise<string> => {
|
||||
// Returns the auth url for the given auth type
|
||||
switch (authType) {
|
||||
case "disabled":
|
||||
return "";
|
||||
case "basic":
|
||||
return "";
|
||||
case "google_oauth": {
|
||||
return await getGoogleOAuthUrlSS();
|
||||
}
|
||||
case "saml": {
|
||||
return await getSAMLAuthUrlSS();
|
||||
}
|
||||
case "oidc": {
|
||||
return await getOIDCAuthUrlSS(nextUrl);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const logoutStandardSS = async (headers: Headers): Promise<Response> => {
|
||||
return await fetch(buildUrl("/auth/logout"), {
|
||||
method: "POST",
|
||||
headers: headers,
|
||||
});
|
||||
};
|
||||
|
||||
const logoutSAMLSS = async (headers: Headers): Promise<Response> => {
|
||||
return await fetch(buildUrl("/auth/saml/logout"), {
|
||||
method: "POST",
|
||||
headers: headers,
|
||||
});
|
||||
};
|
||||
|
||||
export const logoutSS = async (
|
||||
authType: AuthType,
|
||||
headers: Headers
|
||||
): Promise<Response | null> => {
|
||||
switch (authType) {
|
||||
case "disabled":
|
||||
return null;
|
||||
case "saml": {
|
||||
return await logoutSAMLSS(headers);
|
||||
}
|
||||
default: {
|
||||
return await logoutStandardSS(headers);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const getCurrentUserSS = async (): Promise<User | null> => {
|
||||
try {
|
||||
const response = await fetch(buildUrl("/me"), {
|
||||
credentials: "include",
|
||||
next: { revalidate: 0 },
|
||||
headers: {
|
||||
cookie: cookies()
|
||||
.getAll()
|
||||
.map((cookie) => `${cookie.name}=${cookie.value}`)
|
||||
.join("; "),
|
||||
},
|
||||
});
|
||||
if (!response.ok) {
|
||||
return null;
|
||||
}
|
||||
const user = await response.json();
|
||||
return user;
|
||||
} catch (e) {
|
||||
console.log(`Error fetching user: ${e}`);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
export const processCookies = (cookies: ReadonlyRequestCookies): string => {
|
||||
return cookies
|
||||
.getAll()
|
||||
.map((cookie) => `${cookie.name}=${cookie.value}`)
|
||||
.join("; ");
|
||||
};
|
||||
|
||||
export const getNotificationsSS = async (): Promise<Notification[]> => {
|
||||
const response = await fetch(buildUrl("/notifications"));
|
||||
if (!response.ok) {
|
||||
throw new Error("Failed to fetch notifications");
|
||||
}
|
||||
const notifications = await response.json();
|
||||
return notifications;
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user