Skip to content

Commit

Permalink
refactor: explicitly call React functions
Browse files Browse the repository at this point in the history
  • Loading branch information
pamapa committed Aug 20, 2024
1 parent 4f8316d commit af6ef49
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions src/AuthProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import React, {
useCallback,
useEffect,
useMemo,
useReducer,
useRef,
useState,
} from "react";
import React from "react";
import { UserManager, type UserManagerSettings, User } from "oidc-client-ts";
import type {
ProcessResourceOwnerPasswordCredentialsArgs,
Expand Down Expand Up @@ -174,15 +167,15 @@ export const AuthProvider = (props: AuthProviderProps): JSX.Element => {
...userManagerSettings
} = props;

const [userManager] = useState(() => {
const [userManager] = React.useState(() => {
return userManagerProp ??
(UserManagerImpl
? new UserManagerImpl(userManagerSettings as UserManagerSettings)
: ({ settings: userManagerSettings } as UserManager));
});

const [state, dispatch] = useReducer(reducer, initialAuthState);
const userManagerContext = useMemo(
const [state, dispatch] = React.useReducer(reducer, initialAuthState);
const userManagerContext = React.useMemo(
() =>
Object.assign(
{
Expand Down Expand Up @@ -220,9 +213,9 @@ export const AuthProvider = (props: AuthProviderProps): JSX.Element => {
),
[userManager],
);
const didInitialize = useRef(false);
const didInitialize = React.useRef(false);

useEffect(() => {
React.useEffect(() => {
if (!userManager || didInitialize.current) {
return;
}
Expand Down Expand Up @@ -257,7 +250,7 @@ export const AuthProvider = (props: AuthProviderProps): JSX.Element => {
}, [userManager, skipSigninCallback, onSigninCallback, onSignoutCallback, matchSignoutCallback]);

// register to userManager events
useEffect(() => {
React.useEffect(() => {
if (!userManager) return undefined;
// event UserLoaded (e.g. initial load, silent renew success)
const handleUserLoaded = (user: User) => {
Expand Down Expand Up @@ -291,7 +284,7 @@ export const AuthProvider = (props: AuthProviderProps): JSX.Element => {
};
}, [userManager]);

const removeUser = useCallback(async () => {
const removeUser = React.useCallback(async () => {
if (!userManager) unsupportedEnvironment("removeUser");
await userManager.removeUser();
onRemoveUser && await onRemoveUser();
Expand Down

0 comments on commit af6ef49

Please sign in to comment.