@@ -21,6 +21,7 @@ import { GetServerState, ServerState, SetServerState } from './ServerState.js';
21
21
import { registerPostCommands , runPostCommand } from './PostCommands.js' ;
22
22
import { sendJsonError , sendJsonSuccess } from './ServerHelpers.js' ;
23
23
import { ServerEventHandler , ServerEvents } from './ServerEvents.js' ;
24
+ import { User , UserAuthentication } from './Authentication/Authentication.js' ;
24
25
import { AuthDatabase } from './Authentication/AuthDatabase.js' ;
25
26
import { DatabaseImportExport } from './ImportExport.js' ;
26
27
import FirstRunConfig from './FirstRunConfig.js' ;
@@ -33,7 +34,6 @@ import { ServerConfigState } from '../Shared/ServerConfig.js';
33
34
import ServerError from './ServerError.js' ;
34
35
import { default as Sqlite3Store } from './Authentication/SqliteSessionStore.js' ;
35
36
import { ThumbnailManager } from './ThumbnailManager.js' ;
36
- import { UserAuthentication } from './Authentication/Authentication.js' ;
37
37
38
38
/**
39
39
* @typedef {Object } CLIArguments
@@ -509,7 +509,12 @@ async function handlePost(req, res) {
509
509
try {
510
510
if ( Object . prototype . hasOwnProperty . call ( ServerActionMap , endpoint )
511
511
&& typeof ServerActionMap [ endpoint ] === 'function' ) {
512
- await ServerActionMap [ endpoint ] ( res ) ;
512
+ if ( ! Config . useAuth ( ) || User . signedIn ( req ) ) {
513
+ await ServerActionMap [ endpoint ] ( res ) ;
514
+ } else {
515
+ sendJsonError ( res , new ServerError ( 'Not authorized' , 401 ) ) ;
516
+ }
517
+
513
518
return ;
514
519
}
515
520
0 commit comments