Skip to content

Commit

Permalink
Remove the race condition for get header and always have the auth config
Browse files Browse the repository at this point in the history
  • Loading branch information
BearHanded committed Aug 30, 2023
1 parent c6fc847 commit 63109f9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
17 changes: 15 additions & 2 deletions services/ui-src/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ReactDOM from "react-dom";
import { BrowserRouter as Router } from "react-router-dom";
import { ErrorBoundary } from "react-error-boundary";
import { Amplify } from "aws-amplify";
import { Amplify, Auth } from "aws-amplify";
import config from "config";
// utils
import { ApiProvider, UserProvider } from "utils";
Expand All @@ -19,8 +19,21 @@ Amplify.configure({
bucket: config.s3.BUCKET,
identityPoolId: config.cognito.IDENTITY_POOL_ID,
},
Auth: {
mandatorySignIn: true,
region: config.cognito.REGION,
userPoolId: config.cognito.USER_POOL_ID,
identityPoolId: config.cognito.IDENTITY_POOL_ID,
userPoolWebClientId: config.cognito.APP_CLIENT_ID,
oauth: {
domain: config.cognito.APP_CLIENT_DOMAIN,
redirectSignIn: config.cognito.REDIRECT_SIGNIN,
redirectSignOut: config.cognito.REDIRECT_SIGNOUT,
scope: ["email", "openid", "profile"],
responseType: "code",
},
},
});

// LaunchDarkly configuration
const ldClientId = config.REACT_APP_LD_SDK_CLIENT;
(async () => {
Expand Down
18 changes: 0 additions & 18 deletions services/ui-src/src/utils/auth/UserProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,24 +104,6 @@ export const UserProvider = ({ children }: Props) => {
}
}, [isProduction, location]);

// single run configuration
useEffect(() => {
Auth.configure({
mandatorySignIn: true,
region: config.cognito.REGION,
userPoolId: config.cognito.USER_POOL_ID,
identityPoolId: config.cognito.IDENTITY_POOL_ID,
userPoolWebClientId: config.cognito.APP_CLIENT_ID,
oauth: {
domain: config.cognito.APP_CLIENT_DOMAIN,
redirectSignIn: config.cognito.REDIRECT_SIGNIN,
redirectSignOut: config.cognito.REDIRECT_SIGNOUT,
scope: ["email", "openid", "profile"],
responseType: "code",
},
});
}, []);

// re-render on auth state change, checking router location
useEffect(() => {
checkAuthState();
Expand Down

0 comments on commit 63109f9

Please sign in to comment.