Compare commits

..

1 commit

Author SHA1 Message Date
2ab01ec560
Implement authentication logic 2025-04-14 21:01:12 +00:00
8 changed files with 9 additions and 17 deletions

View file

@ -28,7 +28,7 @@ class JWTBearer(HTTPBearer):
if credentials:
if not credentials.scheme == "Bearer":
raise HTTPException(
status_code=401, detail="authentication_scheme_invalid"
status_code=403, detail="authentication_scheme_invalid"
)
try:
token = await token_service.verify_access_token(
@ -36,7 +36,7 @@ class JWTBearer(HTTPBearer):
)
if not token:
raise HTTPException(
status_code=401, detail="token_invalid_or_expired"
status_code=403, detail="token_invalid_or_expired"
)
return token
except InsufficientPermissionsError:
@ -44,4 +44,4 @@ class JWTBearer(HTTPBearer):
except InvalidTokenAudienceError:
raise HTTPException(status_code=403, detail="invalid_token_audience")
else:
raise HTTPException(status_code=401, detail="authorization_code_invalid")
raise HTTPException(status_code=403, detail="authorization_code_invalid")

View file

@ -2,7 +2,7 @@ import axios from 'axios';
import { dev } from '$app/environment';
import { goto } from '$app/navigation';
import { get } from 'svelte/store';
import { persistentSettings, clearLoginState } from '$lib/persistent_store';
import { persistentSettings, clearLoginState } from '$lib/persistent-store';
if (dev) {
axios.defaults.baseURL = "http://localhost:8000/api/v1"
@ -10,9 +10,6 @@ if (dev) {
axios.defaults.baseURL = "/api/v1"
}
// Get access token from local storage
axios.defaults.headers.common['Authorization'] = "Bearer " + get(persistentSettings).accessToken;
function createTokenRefreshInterceptor() {
const interceptor = axios.interceptors.response.use(
(response) => response,
@ -36,9 +33,8 @@ function createTokenRefreshInterceptor() {
refresh_token: get(persistentSettings).refreshToken,
})
.then((response) => {
// Save new tokens
// Save new refresh token
persistentSettings.update(settings => {
settings.accessToken = response.data.access_token
settings.refreshToken = response.data.refresh_token;
return settings;
})
@ -74,7 +70,6 @@ export const login = async function(email: string, password: string) {
.then((response) => {
persistentSettings.update(settings => {
settings.loggedIn = true
settings.accessToken = response.data.access_token
settings.refreshToken = response.data.refresh_token
return settings;
})

View file

@ -3,7 +3,7 @@ import Backend from 'i18next-chained-backend'
import Fetch from 'i18next-fetch-backend'
import LocalStorageBackend from 'i18next-localstorage-backend'
import I18nextBrowserLanguageDetector from 'i18next-browser-languagedetector'
import { createI18nStore } from './i18n_store'
import { createI18nStore } from './i18n-store'
i18next
.use(Backend)

View file

@ -6,7 +6,6 @@ interface PersistedSettings {
friendlyName: string
email: string
role: string
accessToken: string,
refreshToken: string
}
@ -16,7 +15,6 @@ const settingsDefault: PersistedSettings = {
friendlyName: "",
email: "",
role: "member",
accessToken: "",
refreshToken: ""
}
@ -26,7 +24,6 @@ persistentSettings.subscribe((value) => localStorage.persistentSettings = JSON.s
export const clearLoginState = function() {
persistentSettings.update(settings => {
settings.accessToken = "";
settings.refreshToken = "";
settings.loggedIn = false;
settings.friendlyName = "";

View file

@ -1,6 +1,6 @@
<script lang="ts">
import { goto } from '$app/navigation'
import { persistentSettings } from '$lib/persistent_store'
import { persistentSettings } from '$lib/persistent-store'
import i18n from '$lib/i18n'
import { logout } from '$lib/axios.svelte'

View file

@ -1,5 +1,5 @@
<script lang="ts">
import { persistentSettings } from '$lib/persistent_store'
import { persistentSettings } from '$lib/persistent-store'
import { currentDaytime } from '$lib/util'
import i18n from '$lib/i18n'
import DashboardCard from '$lib/component/DashboardCard.svelte'

View file

@ -1,5 +1,5 @@
<script>
import { persistentSettings } from '$lib/persistent_store'
import { persistentSettings } from '$lib/persistent-store'
let { children } = $props()
import '../app.css'
</script>