Skip to content

Commit

Permalink
Fixed TS definitions
Browse files Browse the repository at this point in the history
OKTA-409131
<<<Jenkins Check-In of Tested SHA: a2a0f17 for [email protected]>>>
Artifact: okta-react
Files changed count: 6
PR Link:
  • Loading branch information
denys.oblohin authored and eng-prod-CI-bot-okta committed Jul 16, 2021
1 parent 22add65 commit 80bdeb6
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 6.1.1

### Bug Fixes

- [#146](https://github.com/okta/okta-react/pull/146) Fixed TypeScript definitions

# 6.1.0

### Features
Expand Down
3 changes: 1 addition & 2 deletions src/LoginCallback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const LoginCallback: React.FC<LoginCallbackProps> = ({ errorComponent, loadingCo
const { oktaAuth, authState } = useOktaAuth();
const [callbackError, setCallbackError] = React.useState(null);

const authStateReady = !!authState;
const ErrorReporter = errorComponent || OktaError;
React.useEffect(() => {
if (onAuthResume && oktaAuth.isInteractionRequired?.() ) {
Expand All @@ -40,7 +39,7 @@ const LoginCallback: React.FC<LoginCallbackProps> = ({ errorComponent, loadingCo
});
}, [oktaAuth]);

const authError = authStateReady ? authState.error : null;
const authError = authState?.error;
const displayError = callbackError || authError;
if (displayError) {
return <ErrorReporter error={displayError}/>;
Expand Down
6 changes: 3 additions & 3 deletions src/OktaContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ export type RestoreOriginalUriFunction = (oktaAuth: OktaAuth, originalUri: strin

export interface IOktaContext {
oktaAuth: OktaAuth;
authState: AuthState;
_onAuthRequired: OnAuthRequiredFunction;
authState: AuthState | null;
_onAuthRequired?: OnAuthRequiredFunction;
}

const OktaContext = React.createContext<IOktaContext | null>(null);

export const useOktaAuth = (): IOktaContext => React.useContext(OktaContext);
export const useOktaAuth = (): IOktaContext => React.useContext(OktaContext) as IOktaContext;

export default OktaContext;
4 changes: 2 additions & 2 deletions src/Security.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/

import * as React from 'react';
import { AuthSdkError, OktaAuth } from '@okta/okta-auth-js';
import { AuthSdkError, OktaAuth, AuthState } from '@okta/okta-auth-js';
import OktaContext, { OnAuthRequiredFunction, RestoreOriginalUriFunction } from './OktaContext';
import OktaError from './OktaError';

Expand Down Expand Up @@ -54,7 +54,7 @@ const Security: React.FC<{
oktaAuth.userAgent = `${process.env.PACKAGE_NAME}/${process.env.PACKAGE_VERSION} ${oktaAuth.userAgent}`;

// Update Security provider with latest authState
const handler = (authState) => {
const handler = (authState: AuthState) => {
setAuthState(authState);
};
oktaAuth.authStateManager.subscribe(handler);
Expand Down
2 changes: 1 addition & 1 deletion src/withOktaAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { useOktaAuth, IOktaContext } from './OktaContext';
const withOktaAuth = <P extends IOktaContext>(
ComponentToWrap: React.ComponentType<P>
): React.FC<Omit<P, keyof IOktaContext>> => {
const WrappedComponent = (props) => {
const WrappedComponent = (props: Omit<P, keyof IOktaContext>) => {
const oktaAuthProps = useOktaAuth();
return <ComponentToWrap {...oktaAuthProps as IOktaContext } {...props as P} />;
};
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"jsx": "react",
"moduleResolution": "node",
"strictFunctionTypes": true,
"resolveJsonModule": true
"resolveJsonModule": true,
"strict": true
},
"include": ["src/**/*"],
}

0 comments on commit 80bdeb6

Please sign in to comment.