Skip to content

Commit

Permalink
fix: pass auth code to login container (#197)
Browse files Browse the repository at this point in the history
* fix: pass auth code to login container

* chore: remove try catch
  • Loading branch information
melsener authored Mar 7, 2024
1 parent 7338c2c commit 6133db2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
11 changes: 9 additions & 2 deletions src/client/containers/LoginContainer/LoginContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/client/containers/LoginContainer/hooks/useLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as microsoftTeams from "@microsoft/teams-js";
import { useCallback, useState } from "react";

interface UseLoginParams {
onSuccess: () => void;
onSuccess: (code?: string) => Promise<void>;
}

type UseLoginResult = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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);
});
}, []);

Expand Down

0 comments on commit 6133db2

Please sign in to comment.