Compare commits
2 commits
2ab01ec560
...
148275dd98
Author | SHA1 | Date | |
---|---|---|---|
148275dd98 | |||
be736638bd |
8 changed files with 17 additions and 9 deletions
|
@ -28,7 +28,7 @@ class JWTBearer(HTTPBearer):
|
||||||
if credentials:
|
if credentials:
|
||||||
if not credentials.scheme == "Bearer":
|
if not credentials.scheme == "Bearer":
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=403, detail="authentication_scheme_invalid"
|
status_code=401, detail="authentication_scheme_invalid"
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
token = await token_service.verify_access_token(
|
token = await token_service.verify_access_token(
|
||||||
|
@ -36,7 +36,7 @@ class JWTBearer(HTTPBearer):
|
||||||
)
|
)
|
||||||
if not token:
|
if not token:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=403, detail="token_invalid_or_expired"
|
status_code=401, detail="token_invalid_or_expired"
|
||||||
)
|
)
|
||||||
return token
|
return token
|
||||||
except InsufficientPermissionsError:
|
except InsufficientPermissionsError:
|
||||||
|
@ -44,4 +44,4 @@ class JWTBearer(HTTPBearer):
|
||||||
except InvalidTokenAudienceError:
|
except InvalidTokenAudienceError:
|
||||||
raise HTTPException(status_code=403, detail="invalid_token_audience")
|
raise HTTPException(status_code=403, detail="invalid_token_audience")
|
||||||
else:
|
else:
|
||||||
raise HTTPException(status_code=403, detail="authorization_code_invalid")
|
raise HTTPException(status_code=401, detail="authorization_code_invalid")
|
|
@ -2,7 +2,7 @@ import axios from 'axios';
|
||||||
import { dev } from '$app/environment';
|
import { dev } from '$app/environment';
|
||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
import { get } from 'svelte/store';
|
import { get } from 'svelte/store';
|
||||||
import { persistentSettings, clearLoginState } from '$lib/persistent-store';
|
import { persistentSettings, clearLoginState } from '$lib/persistent_store';
|
||||||
|
|
||||||
if (dev) {
|
if (dev) {
|
||||||
axios.defaults.baseURL = "http://localhost:8000/api/v1"
|
axios.defaults.baseURL = "http://localhost:8000/api/v1"
|
||||||
|
@ -10,6 +10,9 @@ if (dev) {
|
||||||
axios.defaults.baseURL = "/api/v1"
|
axios.defaults.baseURL = "/api/v1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get access token from local storage
|
||||||
|
axios.defaults.headers.common['Authorization'] = "Bearer " + get(persistentSettings).accessToken;
|
||||||
|
|
||||||
function createTokenRefreshInterceptor() {
|
function createTokenRefreshInterceptor() {
|
||||||
const interceptor = axios.interceptors.response.use(
|
const interceptor = axios.interceptors.response.use(
|
||||||
(response) => response,
|
(response) => response,
|
||||||
|
@ -33,8 +36,9 @@ function createTokenRefreshInterceptor() {
|
||||||
refresh_token: get(persistentSettings).refreshToken,
|
refresh_token: get(persistentSettings).refreshToken,
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
// Save new refresh token
|
// Save new tokens
|
||||||
persistentSettings.update(settings => {
|
persistentSettings.update(settings => {
|
||||||
|
settings.accessToken = response.data.access_token
|
||||||
settings.refreshToken = response.data.refresh_token;
|
settings.refreshToken = response.data.refresh_token;
|
||||||
return settings;
|
return settings;
|
||||||
})
|
})
|
||||||
|
@ -70,6 +74,7 @@ export const login = async function(email: string, password: string) {
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
persistentSettings.update(settings => {
|
persistentSettings.update(settings => {
|
||||||
settings.loggedIn = true
|
settings.loggedIn = true
|
||||||
|
settings.accessToken = response.data.access_token
|
||||||
settings.refreshToken = response.data.refresh_token
|
settings.refreshToken = response.data.refresh_token
|
||||||
return settings;
|
return settings;
|
||||||
})
|
})
|
||||||
|
|
|
@ -3,7 +3,7 @@ import Backend from 'i18next-chained-backend'
|
||||||
import Fetch from 'i18next-fetch-backend'
|
import Fetch from 'i18next-fetch-backend'
|
||||||
import LocalStorageBackend from 'i18next-localstorage-backend'
|
import LocalStorageBackend from 'i18next-localstorage-backend'
|
||||||
import I18nextBrowserLanguageDetector from 'i18next-browser-languagedetector'
|
import I18nextBrowserLanguageDetector from 'i18next-browser-languagedetector'
|
||||||
import { createI18nStore } from './i18n-store'
|
import { createI18nStore } from './i18n_store'
|
||||||
|
|
||||||
i18next
|
i18next
|
||||||
.use(Backend)
|
.use(Backend)
|
||||||
|
|
|
@ -6,6 +6,7 @@ interface PersistedSettings {
|
||||||
friendlyName: string
|
friendlyName: string
|
||||||
email: string
|
email: string
|
||||||
role: string
|
role: string
|
||||||
|
accessToken: string,
|
||||||
refreshToken: string
|
refreshToken: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +16,7 @@ const settingsDefault: PersistedSettings = {
|
||||||
friendlyName: "",
|
friendlyName: "",
|
||||||
email: "",
|
email: "",
|
||||||
role: "member",
|
role: "member",
|
||||||
|
accessToken: "",
|
||||||
refreshToken: ""
|
refreshToken: ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +26,7 @@ persistentSettings.subscribe((value) => localStorage.persistentSettings = JSON.s
|
||||||
|
|
||||||
export const clearLoginState = function() {
|
export const clearLoginState = function() {
|
||||||
persistentSettings.update(settings => {
|
persistentSettings.update(settings => {
|
||||||
|
settings.accessToken = "";
|
||||||
settings.refreshToken = "";
|
settings.refreshToken = "";
|
||||||
settings.loggedIn = false;
|
settings.loggedIn = false;
|
||||||
settings.friendlyName = "";
|
settings.friendlyName = "";
|
|
@ -1,6 +1,6 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { goto } from '$app/navigation'
|
import { goto } from '$app/navigation'
|
||||||
import { persistentSettings } from '$lib/persistent-store'
|
import { persistentSettings } from '$lib/persistent_store'
|
||||||
import i18n from '$lib/i18n'
|
import i18n from '$lib/i18n'
|
||||||
import { logout } from '$lib/axios.svelte'
|
import { logout } from '$lib/axios.svelte'
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { persistentSettings } from '$lib/persistent-store'
|
import { persistentSettings } from '$lib/persistent_store'
|
||||||
import { currentDaytime } from '$lib/util'
|
import { currentDaytime } from '$lib/util'
|
||||||
import i18n from '$lib/i18n'
|
import i18n from '$lib/i18n'
|
||||||
import DashboardCard from '$lib/component/DashboardCard.svelte'
|
import DashboardCard from '$lib/component/DashboardCard.svelte'
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<script>
|
<script>
|
||||||
import { persistentSettings } from '$lib/persistent-store'
|
import { persistentSettings } from '$lib/persistent_store'
|
||||||
let { children } = $props()
|
let { children } = $props()
|
||||||
import '../app.css'
|
import '../app.css'
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue