From cf0ba794d754a9d6c6d1281d2ba6bae0a6de0731 Mon Sep 17 00:00:00 2001 From: crazywoola <100913391+crazywoola@users.noreply.github.com> Date: Tue, 28 Nov 2023 20:04:46 +0800 Subject: [PATCH] fix: old webapp url still valid (#1643) --- api/controllers/web/wraps.py | 2 +- web/service/base.ts | 37 ++++++++++++++++-------------------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/api/controllers/web/wraps.py b/api/controllers/web/wraps.py index 14c1390d6b..28a46d329e 100644 --- a/api/controllers/web/wraps.py +++ b/api/controllers/web/wraps.py @@ -40,7 +40,7 @@ def decode_jwt_token(): site = db.session.query(Site).filter(Site.code == app_code).first() if not app_model: raise NotFound() - if not app_code and not site: + if not app_code or not site: raise Unauthorized('Site URL is no longer valid.') if app_model.enable_site is False: raise Unauthorized('Site is disabled.') diff --git a/web/service/base.ts b/web/service/base.ts index 0c07602cb9..62ba655387 100644 --- a/web/service/base.ts +++ b/web/service/base.ts @@ -237,29 +237,24 @@ const baseFetch = ( switch (res.status) { case 401: { if (isPublicAPI) { - Toast.notify({ type: 'error', message: 'Invalid token' }) - return bodyJson.then((data: T) => Promise.reject(data)) + return bodyJson.then((data: ResponseError) => { + Toast.notify({ type: 'error', message: data.message }) + return Promise.reject(data) + }) } const loginUrl = `${globalThis.location.origin}/signin` - if (IS_CE_EDITION) { - bodyJson.then((data: ResponseError) => { - if (data.code === 'not_setup') { - globalThis.location.href = `${globalThis.location.origin}/install` - } - else { - if (location.pathname === '/signin') { - bodyJson.then((data: ResponseError) => { - Toast.notify({ type: 'error', message: data.message }) - }) - } - else { - globalThis.location.href = loginUrl - } - } - }) - return Promise.reject(Error('Unauthorized')) - } - globalThis.location.href = loginUrl + bodyJson.then((data: ResponseError) => { + if (data.code === 'not_setup' && IS_CE_EDITION) + globalThis.location.href = `${globalThis.location.origin}/install` + else if (location.pathname !== '/signin' || !IS_CE_EDITION) + globalThis.location.href = loginUrl + else + Toast.notify({ type: 'error', message: data.message }) + }).catch(() => { + // Handle any other errors + globalThis.location.href = loginUrl + }) + break } case 403: