diff --git a/backend/api/auth/auth.go b/backend/api/auth/auth.go index 91e35b1..1124c52 100644 --- a/backend/api/auth/auth.go +++ b/backend/api/auth/auth.go @@ -20,9 +20,11 @@ func Auth(c *gin.Context) { return } - if requestData.Passcode != passcode { - c.JSON(http.StatusBadRequest, gin.H{"message": "ePasscode Invalid"}) - return + if passcode != "" { + if requestData.Passcode != passcode { + c.JSON(http.StatusBadRequest, gin.H{"message": "Passcode Invalid"}) + return + } } authScopes := os.Getenv("VORTEXNOTES_AUTH_SCOPE") diff --git a/backend/api/configuration/configuration.go b/backend/api/configuration/configuration.go index 3049175..8b166b2 100644 --- a/backend/api/configuration/configuration.go +++ b/backend/api/configuration/configuration.go @@ -9,18 +9,22 @@ import ( func Config(c *gin.Context) { needAuthScopes := os.Getenv("VORTEXNOTES_AUTH_SCOPE") passcode := os.Getenv("VORTEXNOTES_PASSCODE") - auth := "none" + authType := "none" if needAuthScopes == "" { needAuthScopes = "show,create,edit,delete" } if passcode != "" { - auth = "passcode" + authType = "passcode" + c.JSON(http.StatusOK, gin.H{ + "auth_type": authType, + "auth_scope": needAuthScopes, + }) + return } c.JSON(http.StatusOK, gin.H{ - "auth_scope": needAuthScopes, - "auth": auth, + "auth_type": authType, }) } diff --git a/frontend/src/components/Navbar.tsx b/frontend/src/components/Navbar.tsx index 5bbabfb..cdb225f 100644 --- a/frontend/src/components/Navbar.tsx +++ b/frontend/src/components/Navbar.tsx @@ -15,6 +15,7 @@ const Navbar: React.FC = () => { const [theme, setTheme] = useTheme() const onSearch = search.bind(this, input, navigate) + const isPasscodeAuth = localStorage.vortexnotes_auth_type === 'passcode' useEffect(() => { setInput(keywords) @@ -100,9 +101,6 @@ const Navbar: React.FC = () => { )} @@ -124,25 +122,29 @@ const Navbar: React.FC = () => { - {!hasPasscode() && ( -
  • - -
    - - Login -
    - -
  • - )} - {hasPasscode() && ( -
  • - -
    - - Logout -
    - -
  • + {isPasscodeAuth && ( + <> + {!hasPasscode() && ( +
  • + +
    + + Login +
    + +
  • + )} + {hasPasscode() && ( +
  • + +
    + + Logout +
    + +
  • + )} + )} diff --git a/frontend/src/utils/api.ts b/frontend/src/utils/api.ts index d7c4384..c782e23 100644 --- a/frontend/src/utils/api.ts +++ b/frontend/src/utils/api.ts @@ -1,6 +1,11 @@ export async function fetchConfig() { const res = await window.$http.get('config') const authScopes = res.data?.auth_scope + const authType = res.data?.auth_type + + if (authType) { + localStorage.vortexnotes_auth_type = authType + } if (authScopes) { localStorage.vortexnotes_auth_scope = authScopes diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.ts index 35e619c..6331c73 100644 --- a/frontend/src/utils/index.ts +++ b/frontend/src/utils/index.ts @@ -35,9 +35,11 @@ export function onSearch(keywords: string, navigate: NavigateFunction) { } export const hasPermission = (scope: string) => { - if (!localStorage.vortexnotes_passcode) { + if (localStorage.vortexnotes_auth_type === 'passcode') { if (localStorage.vortexnotes_auth_scope?.includes(scope)) { - return false + if (!localStorage.vortexnotes_passcode) { + return false + } } } diff --git a/vortexnotes.run.xml b/vortexnotes.run.xml index 644a048..55ddd2f 100644 --- a/vortexnotes.run.xml +++ b/vortexnotes.run.xml @@ -3,7 +3,7 @@ - +