Skip to content

Commit

Permalink
Anonymous Polish (#3746)
Browse files Browse the repository at this point in the history
* update auth

* k

* address nit
  • Loading branch information
pablonyx authored Jan 23, 2025
1 parent e94ffbc commit 1613a8b
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 12 deletions.
10 changes: 5 additions & 5 deletions web/src/app/admin/settings/AnonymousUserPath.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
"use client";

import useSWR from "swr";
import { useState } from "react";
import { useContext, useState } from "react";

import { PopupSpec } from "@/components/admin/connectors/Popup";
import { Button } from "@/components/ui/button";
import { NEXT_PUBLIC_WEB_DOMAIN } from "@/lib/constants";
import { ClipboardIcon } from "@/components/icons/icons";
import { Input } from "@/components/ui/input";
import { ThreeDotsLoader } from "@/components/Loading";
import { SettingsContext } from "@/components/settings/SettingsProvider";

export function AnonymousUserPath({
setPopup,
}: {
setPopup: (popup: PopupSpec) => void;
}) {
const fetcher = (url: string) => fetch(url).then((res) => res.json());
const settings = useContext(SettingsContext);
const [customPath, setCustomPath] = useState<string | null>(null);

const {
Expand Down Expand Up @@ -116,7 +116,7 @@ export function AnonymousUserPath({
<div className="flex flex-col gap-2 justify-center items-start">
<div className="w-full flex-grow flex items-center rounded-md shadow-sm">
<span className="inline-flex items-center rounded-l-md border border-r-0 border-gray-300 bg-gray-50 px-3 text-gray-500 sm:text-sm h-10">
{NEXT_PUBLIC_WEB_DOMAIN}/anonymous/
{settings?.webDomain}/anonymous/
</span>
<Input
type="text"
Expand All @@ -141,7 +141,7 @@ export function AnonymousUserPath({
className="h-10 px-4"
onClick={() => {
navigator.clipboard.writeText(
`${NEXT_PUBLIC_WEB_DOMAIN}/anonymous/${anonymousUserPath}`
`${settings?.webDomain}/anonymous/${anonymousUserPath}`
);
setPopup({
message: "Invite link copied!",
Expand Down
1 change: 1 addition & 0 deletions web/src/app/admin/settings/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@ export interface CombinedSettings {
customAnalyticsScript: string | null;
isMobile?: boolean;
webVersion: string | null;
webDomain: string | null;
}
8 changes: 5 additions & 3 deletions web/src/app/chat/nrf/NRFPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use client";
import React, { useState, useEffect, useRef } from "react";
import React, { useState, useEffect, useRef, useContext } from "react";
import { useUser } from "@/components/user/UserProvider";
import { usePopup } from "@/components/admin/connectors/Popup";
import {
Expand Down Expand Up @@ -31,11 +31,12 @@ import { useNRFPreferences } from "@/components/context/NRFPreferencesContext";
import { SettingsPanel } from "../../components/nrf/SettingsPanel";
import { ShortcutsDisplay } from "../../components/nrf/ShortcutsDisplay";
import LoginPage from "../../auth/login/LoginPage";
import { AuthType, NEXT_PUBLIC_WEB_DOMAIN } from "@/lib/constants";
import { AuthType } from "@/lib/constants";
import { sendSetDefaultNewTabMessage } from "@/lib/extension/utils";
import { ReadonlyRequestCookies } from "next/dist/server/web/spec-extension/adapters/request-cookies";
import { CHROME_MESSAGE } from "@/lib/extension/constants";
import { ApiKeyModal } from "@/components/llm/ApiKeyModal";
import { SettingsContext } from "@/components/settings/SettingsProvider";

export default function NRFPage({
requestCookies,
Expand All @@ -56,6 +57,7 @@ export default function NRFPage({
const { isNight } = useNightTime();
const { user } = useUser();
const { ccPairs, documentSets, tags, llmProviders } = useChatContext();
const settings = useContext(SettingsContext);

const { popup, setPopup } = usePopup();

Expand Down Expand Up @@ -196,7 +198,7 @@ export default function NRFPage({
}

const newHref =
`${NEXT_PUBLIC_WEB_DOMAIN}/chat?send-on-load=true&user-prompt=` +
`${settings?.webDomain}/chat?send-on-load=true&user-prompt=` +
encodeURIComponent(userMessage) +
filterString;

Expand Down
2 changes: 2 additions & 0 deletions web/src/components/settings/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from "@/app/admin/settings/interfaces";
import {
CUSTOM_ANALYTICS_ENABLED,
HOST_URL,
SERVER_SIDE_ONLY__PAID_ENTERPRISE_FEATURES_ENABLED,
} from "@/lib/constants";
import { fetchSS } from "@/lib/utilsSS";
Expand Down Expand Up @@ -99,6 +100,7 @@ export async function fetchSettingsSS(): Promise<CombinedSettings | null> {
enterpriseSettings,
customAnalyticsScript,
webVersion,
webDomain: HOST_URL,
};

return combinedSettings;
Expand Down
9 changes: 8 additions & 1 deletion web/src/lib/chat/fetchChatData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,14 @@ export async function fetchChatData(searchParams: {
);
const sidebarToggled = requestCookies.get(SIDEBAR_TOGGLED_COOKIE_NAME);

const toggleSidebar = sidebarToggled
// IF user is an anoymous user, we don't want to show the sidebar (they have no access to chat history)
const toggleSidebar =
!user?.is_anonymous_user &&
(sidebarToggled
? sidebarToggled.value.toLocaleLowerCase() == "true" || false
: NEXT_PUBLIC_DEFAULT_SIDEBAR_OPEN);

sidebarToggled
? sidebarToggled.value.toLocaleLowerCase() == "true" || false
: NEXT_PUBLIC_DEFAULT_SIDEBAR_OPEN;

Expand Down
3 changes: 0 additions & 3 deletions web/src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,3 @@ export const NEXT_PUBLIC_DELETE_ALL_CHATS_ENABLED =

export const NEXT_PUBLIC_ENABLE_CHROME_EXTENSION =
process.env.NEXT_PUBLIC_ENABLE_CHROME_EXTENSION?.toLowerCase() === "true";

export const NEXT_PUBLIC_WEB_DOMAIN =
process.env.NEXT_PUBLIC_WEB_DOMAIN || "http://127.0.0.1:3000";
1 change: 1 addition & 0 deletions web/src/lib/userSS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export const getAuthUrlSS = async (
nextUrl: string | null
): Promise<string> => {
// Returns the auth url for the given auth type

switch (authType) {
case "disabled":
return "";
Expand Down

0 comments on commit 1613a8b

Please sign in to comment.