add cloud auth type

This commit is contained in:
pablodanswer
2024-10-20 12:34:58 -07:00
parent b4e975013c
commit 1cad9c7b3d
10 changed files with 47 additions and 12 deletions

View File

@@ -9,7 +9,7 @@ export function SignInButton({
authType: AuthType;
}) {
let button;
if (authType === "google_oauth") {
if (authType === "google_oauth" || authType === "cloud") {
button = (
<div className="mx-auto flex">
<div className="my-auto mr-2">
@@ -42,7 +42,7 @@ export function SignInButton({
return (
<a
className="mt-6 py-3 w-72 text-text-100 bg-accent flex rounded cursor-pointer hover:bg-indigo-800"
className="mx-auto mt-6 py-3 w-72 text-text-100 bg-accent flex rounded cursor-pointer hover:bg-indigo-800"
href={authorizeUrl}
>
{button}

View File

@@ -71,6 +71,8 @@ const Page = async ({
if (authTypeMetadata?.autoRedirect && authUrl && !autoRedirectDisabled) {
return redirect(authUrl);
}
console.log("authTypeMetadata");
console.log(authTypeMetadata);
return (
<AuthFlowContainer>
@@ -78,7 +80,7 @@ const Page = async ({
<HealthCheckBanner />
</div>
<div>
<div className="flex flex-col justify-center">
{authUrl && authTypeMetadata && (
<>
<h2 className="text-center text-xl text-strong font-bold">
@@ -92,6 +94,17 @@ const Page = async ({
</>
)}
{authTypeMetadata?.authType === "cloud" && (
<div className="mt-4 w-full justify-center">
<div className="flex items-center w-full my-4">
<div className="flex-grow border-t border-gray-300"></div>
<span className="px-4 text-gray-500">or</span>
<div className="flex-grow border-t border-gray-300"></div>
</div>
<EmailPasswordForm shouldVerify={true} />
</div>
)}
{authTypeMetadata?.authType === "basic" && (
<Card className="mt-4 w-96">
<div className="flex">

View File

@@ -1,4 +1,10 @@
export type AuthType = "disabled" | "basic" | "google_oauth" | "oidc" | "saml";
export type AuthType =
| "disabled"
| "basic"
| "google_oauth"
| "oidc"
| "saml"
| "cloud";
export const HOST_URL = process.env.WEB_DOMAIN || "http://127.0.0.1:3000";
export const HEADER_HEIGHT = "h-16";

View File

@@ -2,7 +2,7 @@ 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";
import { AuthType, SERVER_SIDE_ONLY__CLOUD_ENABLED } from "./constants";
export interface AuthTypeMetadata {
authType: AuthType;
@@ -18,7 +18,13 @@ export const getAuthTypeMetadataSS = async (): Promise<AuthTypeMetadata> => {
const data: { auth_type: string; requires_verification: boolean } =
await res.json();
const authType = data.auth_type as AuthType;
let authType: AuthType;
if (SERVER_SIDE_ONLY__CLOUD_ENABLED) {
authType = "cloud";
} else {
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
@@ -78,6 +84,7 @@ export const getAuthUrlSS = async (
authType: AuthType,
nextUrl: string | null
): Promise<string> => {
console.log(authType);
// Returns the auth url for the given auth type
switch (authType) {
case "disabled":
@@ -87,6 +94,12 @@ export const getAuthUrlSS = async (
case "google_oauth": {
return await getGoogleOAuthUrlSS();
}
case "cloud": {
console.log("returning cloud auth url");
const value = await getGoogleOAuthUrlSS();
console.log(value);
return value;
}
case "saml": {
return await getSAMLAuthUrlSS();
}