From 6133db2d710184bcf126913027c4a5abddb51e7e Mon Sep 17 00:00:00 2001 From: melsener Date: Thu, 7 Mar 2024 15:42:46 +0300 Subject: [PATCH] fix: pass auth code to login container (#197) * fix: pass auth code to login container * chore: remove try catch --- .../containers/LoginContainer/LoginContainer.tsx | 11 +++++++++-- .../containers/LoginContainer/hooks/useLogin.ts | 2 +- .../ZeplinAuthEndContainer.tsx | 13 ++----------- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/client/containers/LoginContainer/LoginContainer.tsx b/src/client/containers/LoginContainer/LoginContainer.tsx index 5bad5dbb..3d7e7201 100644 --- a/src/client/containers/LoginContainer/LoginContainer.tsx +++ b/src/client/containers/LoginContainer/LoginContainer.tsx @@ -5,7 +5,7 @@ import { useLogin } from "./hooks"; import { Login } from "./components"; import { Loader } from "@fluentui/react-northstar"; import { useRouter } from "next/router"; -import { url } from "../../lib"; +import { url, requester, storage } from "../../lib"; export const LoginContainer: FunctionComponent = () => { const { @@ -21,7 +21,14 @@ export const LoginContainer: FunctionComponent = () => { const { isInitializeLoading } = useInitialize(); const [login, { loginError }] = useLogin({ - onSuccess: () => { + onSuccess: async (code?: string) => { + try { + const { accessToken, refreshToken } = await requester.createAuthToken(String(code)); + storage.setAccessToken(accessToken); + storage.setRefreshToken(refreshToken); + } catch (err) { + // TODO: log to sentry + } replace(id ? url.getConfigurationUpdateUrl({ channel: channel as string, diff --git a/src/client/containers/LoginContainer/hooks/useLogin.ts b/src/client/containers/LoginContainer/hooks/useLogin.ts index 87645546..12bee1e0 100644 --- a/src/client/containers/LoginContainer/hooks/useLogin.ts +++ b/src/client/containers/LoginContainer/hooks/useLogin.ts @@ -2,7 +2,7 @@ import * as microsoftTeams from "@microsoft/teams-js"; import { useCallback, useState } from "react"; interface UseLoginParams { - onSuccess: () => void; + onSuccess: (code?: string) => Promise; } type UseLoginResult = [ diff --git a/src/client/containers/ZeplinAuthEndContainer/ZeplinAuthEndContainer.tsx b/src/client/containers/ZeplinAuthEndContainer/ZeplinAuthEndContainer.tsx index 7f38cc0f..cabbb0fe 100644 --- a/src/client/containers/ZeplinAuthEndContainer/ZeplinAuthEndContainer.tsx +++ b/src/client/containers/ZeplinAuthEndContainer/ZeplinAuthEndContainer.tsx @@ -3,8 +3,6 @@ import { useRouter } from "next/router"; import * as microsoftTeams from "@microsoft/teams-js"; import { Loader } from "@fluentui/react-northstar"; -import { requester, storage } from "../../lib"; - export const ZeplinAuthEndContainer: FunctionComponent = () => { const { query: { @@ -14,20 +12,13 @@ export const ZeplinAuthEndContainer: FunctionComponent = () => { } = useRouter(); useEffect(() => { - microsoftTeams.initialize(async () => { + microsoftTeams.initialize(() => { if (error) { microsoftTeams.authentication.notifyFailure(String(error)); return; } - try { - const { accessToken, refreshToken } = await requester.createAuthToken(String(code)); - storage.setAccessToken(accessToken); - storage.setRefreshToken(refreshToken); - microsoftTeams.authentication.notifySuccess(); - } catch (tokenError) { - microsoftTeams.authentication.notifyFailure((tokenError as Error)?.message ?? `Unknown error ${tokenError}`); - } + microsoftTeams.authentication.notifySuccess(code as string); }); }, []);