From 106d3b1fa1e316ba1306d3b7f136f1fcc16fd4ee Mon Sep 17 00:00:00 2001 From: John Costa Date: Sun, 5 Oct 2025 21:25:44 +0100 Subject: [PATCH] fix? --- .../src/components/protected-route/index.tsx | 17 +---------------- frontend/src/network/index.ts | 13 +++++++++++++ .../ios/Sources/SharedToken.swift | 1 + 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/frontend/src/components/protected-route/index.tsx b/frontend/src/components/protected-route/index.tsx index c8dde83..86fc3ce 100644 --- a/frontend/src/components/protected-route/index.tsx +++ b/frontend/src/components/protected-route/index.tsx @@ -1,8 +1,6 @@ import { Navigate } from "@solidjs/router"; -import { platform } from "@tauri-apps/plugin-os"; import { jwtDecode } from "jwt-decode"; -import { Component, createSignal, ParentProps, Show } from "solid-js"; -import { save_token } from "tauri-plugin-ios-shared-token-api"; +import { Component, ParentProps, Show } from "solid-js"; import { InferOutput, literal, number, object, parse, pipe, string, transform } from "valibot"; export const isTokenValid = (): boolean => { @@ -34,29 +32,16 @@ export const getTokenProperties = (token: string): InferOutput = (props) => { const isValid = isTokenValid(); - const [error, setError] = createSignal(); if (isValid) { const token = localStorage.getItem("refresh"); if (token == null) { throw new Error("unreachable"); } - - if (platform() === "ios") { - // iOS share extension is a seperate process to the App. - // Therefore, we need to share our access token somewhere both the App & Share Extension can access - // This involves App Groups. - save_token(token) - .then(() => console.log("Saved token!!!")) - .catch((e) => setError("Couldnt save token: " + e)); - } } return ( }> - - {e =>

{e()}

} -
{props.children}
); diff --git a/frontend/src/network/index.ts b/frontend/src/network/index.ts index f0dadae..1c859f6 100644 --- a/frontend/src/network/index.ts +++ b/frontend/src/network/index.ts @@ -1,5 +1,7 @@ import { getTokenProperties } from "@components/protected-route"; import { fetch } from "@tauri-apps/plugin-http"; +import { platform } from "@tauri-apps/plugin-os"; +import { save_token } from "tauri-plugin-ios-shared-token-api"; import { type InferOutput, @@ -45,6 +47,17 @@ export const getAccessToken = async (): Promise => { throw new Error("you are not logged in") } + + + if (platform() === "ios") { + // iOS share extension is a seperate process to the App. + // Therefore, we need to share our access token somewhere both the App & Share Extension can access + // This involves App Groups. + save_token(refreshToken!) + .then(() => console.log("Saved token!!!")) + .catch(console.error); + } + // FIX: Check what getTokenProperties returns const tokenProps = getTokenProperties(accessToken!); diff --git a/tauri-plugin-ios-shared-token/ios/Sources/SharedToken.swift b/tauri-plugin-ios-shared-token/ios/Sources/SharedToken.swift index da79b41..ccf542c 100644 --- a/tauri-plugin-ios-shared-token/ios/Sources/SharedToken.swift +++ b/tauri-plugin-ios-shared-token/ios/Sources/SharedToken.swift @@ -24,6 +24,7 @@ class SharedToken: Plugin { } sharedDefaults.set(token, forKey: sharedTokenKey) + sharedDefaults.synchronize() invoke.resolve() } }