From d7f074b02383ef8574c04764c628ffaa792c8e54 Mon Sep 17 00:00:00 2001 From: Violet Caulfield Date: Sun, 19 Jan 2025 09:57:58 -0600 Subject: [PATCH] singleton stuff --- api/client.ts | 13 +++++++++++++ index.js | 6 +++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/api/client.ts b/api/client.ts index 948a1708..d15ca7d4 100644 --- a/api/client.ts +++ b/api/client.ts @@ -64,6 +64,13 @@ export default class Client { Client.instance.removeCredentials() } + public static switchUser(): void { + if (!Client.#instance) + Client.instance; + + Client.instance.removeUser(); + } + private setAndPersistUser(user: JellifyUser) { this.user = user; @@ -94,6 +101,12 @@ export default class Client { storage.delete(MMKVStorageKeys.User) } + private removeUser() { + this.user = undefined; + + storage.delete(MMKVStorageKeys.User) + } + /** * Uses the jellifyClient to create a public Jellyfin API instance. * @param serverUrl The URL of the Jellyfin server diff --git a/index.js b/index.js index 0c6395f8..e78588c2 100644 --- a/index.js +++ b/index.js @@ -4,8 +4,8 @@ import App from './App'; import {name as appName} from './app.json'; import { PlaybackService } from './player/service' import TrackPlayer from 'react-native-track-player'; -import { Client } from './api/client'; +import Client from './api/client'; -Client.instance; AppRegistry.registerComponent(appName, () => App); -TrackPlayer.registerPlaybackService(() => PlaybackService); \ No newline at end of file +TrackPlayer.registerPlaybackService(() => PlaybackService); +Client.instance; \ No newline at end of file