From 58581796dfef936627da5fc0a2f8849d589625b7 Mon Sep 17 00:00:00 2001 From: Liam Stevens <8955671+liamstevens111@users.noreply.github.com> Date: Thu, 16 Feb 2023 17:57:23 +0700 Subject: [PATCH] [#21] Add UserToken helper module abstraction that uses LocalStorage for tokens --- src/helpers/localStorage.ts | 1 - src/helpers/userToken.ts | 12 ++++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) delete mode 100644 src/helpers/localStorage.ts create mode 100644 src/helpers/userToken.ts diff --git a/src/helpers/localStorage.ts b/src/helpers/localStorage.ts deleted file mode 100644 index cb0ff5c..0000000 --- a/src/helpers/localStorage.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/src/helpers/userToken.ts b/src/helpers/userToken.ts new file mode 100644 index 0000000..1eef217 --- /dev/null +++ b/src/helpers/userToken.ts @@ -0,0 +1,12 @@ +type UserToken = { + accessToken: string; + refreshToken: string; +}; + +export const getToken = (): UserToken | string => { + return JSON.parse(localStorage.getItem('UserToken') || ''); +}; + +export const setToken = (token: UserToken) => { + localStorage.setItem('UserToken', JSON.stringify(token)); +};