Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita2b39bc

Browse files
authored
Simplify login options (#1953)
* remove login modal, messagesBeforeLogin and clean up options* ensure loginEnabled
1 parent2ab2654 commita2b39bc

File tree

12 files changed

+24
-184
lines changed

12 files changed

+24
-184
lines changed

‎.env‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ MONGODB_DIRECT_CONNECTION=false
2020

2121

2222
## Public app configuration ##
23-
PUBLIC_APP_GUEST_MESSAGE=# a message to the guest user. If not set, no message will be shown. Only used if you have authentication enabled.
2423
PUBLIC_APP_NAME=ChatUI# name used as title throughout the app
2524
PUBLIC_APP_ASSETS=chatui# used to find logos & favicons in static/$PUBLIC_APP_ASSETS
2625
PUBLIC_APP_DESCRIPTION="Making the community's best AI chat models available to everyone."# description used throughout the app
@@ -32,11 +31,12 @@ PUBLIC_PLAUSIBLE_SCRIPT_URL=
3231
PUBLIC_APPLE_APP_ID=
3332

3433
COUPLE_SESSION_WITH_COOKIE_NAME=
34+
# when OPEN_ID is configured, users are required to login after the welcome modal
3535
OPENID_CLIENT_ID=
3636
OPENID_CLIENT_SECRET=
3737
OPENID_SCOPES="openid profile inference-api"
3838
USE_USER_TOKEN=
39-
AUTOMATIC_LOGIN=
39+
AUTOMATIC_LOGIN=# if true authentication is required on all routes
4040

4141
### Local Storage ###
4242
MONGO_STORAGE_PATH=# where is the db folder stored
@@ -88,7 +88,6 @@ PUBLIC_LLM_ROUTER_ALIAS_ID=omni
8888
### Authentication ###
8989
# Parameters to enable open id login
9090
OPENID_CONFIG=
91-
MESSAGES_BEFORE_LOGIN=# how many messages a user can send in a conversation before having to login. set to 0 to force login right away
9291
# if it's defined, only these emails will be allowed to use login
9392
ALLOWED_USER_EMAILS=[]
9493
# If it's defined, users with emails matching these domains will also be allowed to use login

‎chart/env/prod.yaml‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ envVars:
5050
COUPLE_SESSION_WITH_COOKIE_NAME:"token"
5151
OPENID_SCOPES:"openid profile inference-api"
5252
USE_USER_TOKEN:"true"
53-
AUTOMATIC_LOGIN:"true"
53+
AUTOMATIC_LOGIN:"false"
5454

5555
ADDRESS_HEADER:"X-Forwarded-For"
5656
APP_BASE:"/chat"
@@ -62,7 +62,6 @@ envVars:
6262
LOG_LEVEL:"debug"
6363

6464
OPENAI_BASE_URL:"https://router.huggingface.co/v1"
65-
MESSAGES_BEFORE_LOGIN:"999"
6665
PUBLIC_APP_ASSETS:"huggingchat"
6766
PUBLIC_APP_NAME:"HuggingChat"
6867
PUBLIC_APP_DESCRIPTION:"Making the community's best AI chat models available to everyone"

‎src/hooks.server.ts‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { collections } from "$lib/server/database";
44
import{base}from"$app/paths";
55
import{
66
authenticateRequest,
7+
loginEnabled,
78
refreshSessionCookie,
8-
requiresUser,
99
triggerOauthFlow,
1010
}from"$lib/server/auth";
1111
import{ERROR_MESSAGES}from"$lib/stores/errors";
@@ -139,9 +139,9 @@ export const handle: Handle = async ({ event, resolve }) => {
139139
event.locals.sessionId=auth.sessionId;
140140

141141
if(
142+
loginEnabled&&
142143
!auth.user&&
143144
config.AUTOMATIC_LOGIN==="true"&&
144-
!event.url.pathname.startsWith(`${base}/`)&&
145145
!event.url.pathname.startsWith(`${base}/login`)&&
146146
!event.url.pathname.startsWith(`${base}/healthcheck`)
147147
){
@@ -199,20 +199,14 @@ export const handle: Handle = async ({ event, resolve }) => {
199199
}
200200

201201
if(
202+
loginEnabled&&
203+
!event.locals.user&&
202204
!event.url.pathname.startsWith(`${base}/login`)&&
203205
!event.url.pathname.startsWith(`${base}/admin`)&&
204206
!event.url.pathname.startsWith(`${base}/settings`)&&
205207
!["GET","OPTIONS","HEAD"].includes(event.request.method)
206208
){
207-
if(
208-
!event.locals.user&&
209-
requiresUser&&
210-
!((config.MESSAGES_BEFORE_LOGIN ?parseInt(config.MESSAGES_BEFORE_LOGIN) :0)>0)
211-
){
212-
returnerrorResponse(401,ERROR_MESSAGES.authOnly);
213-
}
214-
215-
// Ethics disclaimer gating removed
209+
returnerrorResponse(401,ERROR_MESSAGES.authOnly);
216210
}
217211

218212
letreplaced=false;

‎src/lib/components/LoginModal.svelte‎

Lines changed: 0 additions & 64 deletions
This file was deleted.

‎src/lib/components/NavMenu.svelte‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
3434
interfaceProps {
3535
conversations:ConvSidebar[];
36-
canLogin:boolean;
3736
user:LayoutData["user"];
3837
p?:number;
3938
ondeleteConversation?: (id:string)=>void;

‎src/lib/components/chat/ChatInput.svelte‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
66
importHoverTooltipfrom"$lib/components/HoverTooltip.svelte";
77
importIconPaperclipfrom"$lib/components/icons/IconPaperclip.svelte";
8-
import {page }from"$app/state";
9-
import {loginModalOpen }from"$lib/stores/loginModal";
108
119
import {isVirtualKeyboard }from"$lib/utils/isVirtualKeyboard";
1210
interfaceProps {
@@ -158,12 +156,6 @@
158156
onkeydown={handleKeydown}
159157
oncompositionstart={()=> (isCompositionOn=true)}
160158
oncompositionend={()=> (isCompositionOn=false)}
161-
onbeforeinput={(ev)=> {
162-
if (page.data.loginRequired) {
163-
ev.preventDefault();
164-
$loginModalOpen=true;
165-
}
166-
}}
167159
{placeholder}
168160
{disabled}
169161
onfocus={handleFocus}

‎src/lib/components/chat/ChatWindow.svelte‎

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
importChatInputfrom"./ChatInput.svelte";
1010
importStopGeneratingBtnfrom"../StopGeneratingBtn.svelte";
1111
importtype {Model }from"$lib/types/Model";
12-
import {page }from"$app/state";
1312
importFileDropzonefrom"./FileDropzone.svelte";
1413
importRetryBtnfrom"../RetryBtn.svelte";
1514
importfile2base64from"$lib/utils/file2base64";
@@ -31,7 +30,6 @@
3130
3231
import {fly }from"svelte/transition";
3332
import {cubicInOut }from"svelte/easing";
34-
import {loginModalOpen }from"$lib/stores/loginModal";
3533
3634
import {isVirtualKeyboard }from"$lib/utils/isVirtualKeyboard";
3735
@@ -276,10 +274,6 @@
276274
277275
function triggerPrompt(prompt:string) {
278276
if (loading)return;
279-
if (page.data.loginRequired) {
280-
$loginModalOpen=true;
281-
return;
282-
}
283277
draft=prompt;
284278
handleSubmit();
285279
}
@@ -377,11 +371,7 @@
377371
<ChatIntroduction
378372
{currentModel}
379373
onmessage={(content)=> {
380-
if (page.data.loginRequired) {
381-
$loginModalOpen=true;
382-
}else {
383-
onmessage?.(content);
384-
}
374+
onmessage?.(content);
385375
}}
386376
/>
387377
{/if}

‎src/lib/server/api/routes/groups/misc.ts‎

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import{Elysia}from"elysia";
22
import{authPlugin}from"../../authPlugin";
3-
import{requiresUser}from"$lib/server/auth";
3+
import{loginEnabled}from"$lib/server/auth";
44
import{collections}from"$lib/server/database";
55
import{authCondition}from"$lib/server/auth";
66
import{config}from"$lib/server/config";
@@ -12,51 +12,16 @@ import { logger } from "$lib/server/logger";
1212
exportinterfaceFeatureFlags{
1313
enableAssistants:boolean;
1414
loginEnabled:boolean;
15-
loginRequired:boolean;
16-
guestMode:boolean;
1715
isAdmin:boolean;
1816
}
1917

2018
exportconstmisc=newElysia()
2119
.use(authPlugin)
2220
.get("/public-config",async()=>config.getPublicConfig())
2321
.get("/feature-flags",async({ locals})=>{
24-
letloginRequired=false;
25-
constmessagesBeforeLogin=config.MESSAGES_BEFORE_LOGIN
26-
?parseInt(config.MESSAGES_BEFORE_LOGIN)
27-
:0;
28-
constnConversations=awaitcollections.conversations.countDocuments(authCondition(locals));
29-
30-
if(requiresUser&&!locals.user){
31-
if(messagesBeforeLogin===0){
32-
loginRequired=true;
33-
}elseif(nConversations>=messagesBeforeLogin){
34-
loginRequired=true;
35-
}else{
36-
// get the number of messages where `from === "assistant"` across all conversations.
37-
consttotalMessages=
38-
(
39-
awaitcollections.conversations
40-
.aggregate([
41-
{$match:{ ...authCondition(locals),"messages.from":"assistant"}},
42-
{$project:{messages:1}},
43-
{$limit:messagesBeforeLogin+1},
44-
{$unwind:"$messages"},
45-
{$match:{"messages.from":"assistant"}},
46-
{$count:"messages"},
47-
])
48-
.toArray()
49-
)[0]?.messages??0;
50-
51-
loginRequired=totalMessages>=messagesBeforeLogin;
52-
}
53-
}
54-
5522
return{
5623
enableAssistants:config.ENABLE_ASSISTANTS==="true",
57-
loginEnabled:requiresUser,// misnomer, this is actually whether the feature is available, not required
58-
loginRequired,
59-
guestMode:requiresUser&&messagesBeforeLogin>0,
24+
loginEnabled,// login feature is on when OID is configured
6025
isAdmin:locals.isAdmin,
6126
}satisfiesFeatureFlags;
6227
})

‎src/lib/server/auth.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export const OIDConfig = z
5454
})
5555
.parse(JSON5.parse(config.OPENID_CONFIG||"{}"));
5656

57-
exportconstrequiresUser=!!OIDConfig.CLIENT_ID&&!!OIDConfig.CLIENT_SECRET;
57+
exportconstloginEnabled=!!OIDConfig.CLIENT_ID&&!!OIDConfig.CLIENT_SECRET;
5858

5959
constsameSite=z
6060
.enum(["lax","none","strict"])

‎src/lib/stores/loginModal.ts‎

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp