Implemented Native Token Storage other than Cookies
This commit is contained in:
@@ -1,10 +1,19 @@
|
||||
import {Preferences} from "@capacitor/preferences";
|
||||
|
||||
export default defineNuxtPlugin(() => {
|
||||
const api = $fetch.create({
|
||||
baseURL: /*"http://localhost:3100"*/ "https://backend.fedeo.io",
|
||||
baseURL: /*"http://192.168.1.227:3100"*/ "https://backend.fedeo.io",
|
||||
credentials: "include",
|
||||
onRequest({ options }) {
|
||||
async onRequest({options}) {
|
||||
// Token aus Cookie holen
|
||||
let token = useCookie("token").value
|
||||
let token: string | null | undefined = ""
|
||||
if (await useCapacitor().getIsNative()) {
|
||||
const {value} = await Preferences.get({key: 'token'});
|
||||
token = value
|
||||
} else {
|
||||
token = useCookie("token").value
|
||||
}
|
||||
|
||||
|
||||
// Falls im Request explizit ein anderer JWT übergeben wird → diesen verwenden
|
||||
if (options.context && (options.context as any).jwt) {
|
||||
|
||||
Reference in New Issue
Block a user