From 9a72169819f89fea2d87e1ec574db12f6085958a Mon Sep 17 00:00:00 2001 From: Pascal Hartig Date: Mon, 27 Jun 2022 04:42:11 -0700 Subject: [PATCH] Expose is-logged-in endpoint Summary: Make it possible to ask whether a user is logged in. This won't tackle token expiration but it's consistent with the internal API we have through the `isLoggedIn` atom. Reviewed By: lblasa Differential Revision: D37422274 fbshipit-source-id: 2d3a5e27f5dbbe866d5392403e690faf2f1156b2 --- desktop/flipper-common/src/server-types.tsx | 1 + desktop/flipper-server-core/src/FlipperServerImpl.tsx | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/desktop/flipper-common/src/server-types.tsx b/desktop/flipper-common/src/server-types.tsx index 323283c3a..a9f1d67f5 100644 --- a/desktop/flipper-common/src/server-types.tsx +++ b/desktop/flipper-common/src/server-types.tsx @@ -302,6 +302,7 @@ export type FlipperServerCommands = { messages: {category: string; message: string}[], ) => Promise; shutdown: () => Promise; + 'is-logged-in': () => Promise; }; export type GraphResponse = { diff --git a/desktop/flipper-server-core/src/FlipperServerImpl.tsx b/desktop/flipper-server-core/src/FlipperServerImpl.tsx index 213e6493c..9b797773c 100644 --- a/desktop/flipper-server-core/src/FlipperServerImpl.tsx +++ b/desktop/flipper-server-core/src/FlipperServerImpl.tsx @@ -481,6 +481,14 @@ export class FlipperServerImpl implements FlipperServer { shutdown: async () => { process.exit(0); }, + 'is-logged-in': async () => { + try { + const token = await this.keytarManager.retrieveToken(SERVICE_FLIPPER); + return !!token; + } catch (e) { + return false; + } + }, }; registerDevice(device: ServerDevice) {