From af397f83ec0bf161b65567d4d3d31d525bc15150 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Sun, 13 Feb 2022 23:59:12 -0500 Subject: [PATCH] add shared logout code --- packages/components/src/api/session/Logout.ts | 25 ++++++++++++++++ .../src/migration/MigrationTopNav_Session.tsx | 29 +++++-------------- 2 files changed, 32 insertions(+), 22 deletions(-) create mode 100644 packages/components/src/api/session/Logout.ts diff --git a/packages/components/src/api/session/Logout.ts b/packages/components/src/api/session/Logout.ts new file mode 100644 index 0000000000..ea8b7a8242 --- /dev/null +++ b/packages/components/src/api/session/Logout.ts @@ -0,0 +1,25 @@ +import { ApiConfig } from "../ApiConfig"; + +interface ResponsePayload { + success: boolean, +} + +export async function Logout() : Promise { + const endpoint = new ApiConfig().logout(); + + return await fetch(endpoint, { + method: 'POST', + headers: { + 'Accept': 'application/json', + }, + credentials: 'include', + }) + .then(res => res.json()) + .then(res => { + const response : ResponsePayload = res; + return response.success; + }) + .catch(e => { + return false; + }); +} diff --git a/packages/fakeyou/src/migration/MigrationTopNav_Session.tsx b/packages/fakeyou/src/migration/MigrationTopNav_Session.tsx index 6e5739c4c2..a74e867f22 100644 --- a/packages/fakeyou/src/migration/MigrationTopNav_Session.tsx +++ b/packages/fakeyou/src/migration/MigrationTopNav_Session.tsx @@ -1,5 +1,6 @@ import React from 'react'; import { SessionWrapper } from '@storyteller/components/src/session/SessionWrapper'; +import { Logout } from '@storyteller/components/src/api/session/Logout'; import { Link, useHistory } from 'react-router-dom'; import { ApiConfig } from '@storyteller/components'; import { t } from 'i18next'; @@ -18,26 +19,10 @@ function MigrationTopNavSession(props: Props) { return