Skip to content

Commit

Permalink
Log auth (#11894)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmrabian authored Oct 24, 2024
1 parent 921ee2f commit 3b4f17c
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion services/ui-src/src/utils/auth/UserProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import {
import { useLocation } from "react-router-dom";
import {
fetchAuthSession,
getCurrentUser,
signInWithRedirect,
signOut,
} from "aws-amplify/auth";
import { Hub } from "aws-amplify/utils";
import config from "config";
// utils
import { initAuthManager, updateTimeout, getExpiration, useStore } from "utils";
Expand All @@ -25,8 +27,26 @@ export const UserContext = createContext<UserContextShape>({
getExpiration: () => {},
});

/* eslint-disable no-console */
Hub.listen("auth", async ({ payload }) => {
switch (payload.event) {
case "signInWithRedirect":
// eslint-disable-next-line no-case-declarations
const user = await getCurrentUser();
console.log(user.username);
break;
case "signInWithRedirect_failure":
console.log("payload", payload);
break;
}
});

const authenticateWithIDM = async () => {
await signInWithRedirect({ provider: { custom: "Okta" } });
try {
await signInWithRedirect({ provider: { custom: "Okta" } });
} catch (err: any) {
console.error("error", err);
}
};

export const UserProvider = ({ children }: Props) => {
Expand Down

0 comments on commit 3b4f17c

Please sign in to comment.