From c80312136bb3adb0637220531a03e71db528d4b3 Mon Sep 17 00:00:00 2001 From: Nagy Viktor Date: Wed, 25 Sep 2024 02:19:05 +0200 Subject: [PATCH] moving react dependency to peer dependencies --- packages/sn-auth-react/package.json | 10 ++++----- .../components/authentication-provider.tsx | 21 ++++++++++--------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/packages/sn-auth-react/package.json b/packages/sn-auth-react/package.json index 5c9949a41..bb11774fd 100644 --- a/packages/sn-auth-react/package.json +++ b/packages/sn-auth-react/package.json @@ -1,6 +1,6 @@ { "name": "@sensenet/sn-auth-react", - "version": "1.0.0", + "version": "1.0.2", "main": "./dist/cjs/index.js", "module": "./dist/esm/index.js", "typings": "./dist/types/index.d.ts", @@ -30,15 +30,13 @@ }, "peerDependencies": { "@material-ui/core": "^4.0.0", - "react": ">=16.8.0", - "react-dom": ">=16.8.0" + "react": "^17.0.0 || ^18.0.0", + "react-dom": "^17.0.0 || ^18.0.0" }, "dependencies": { "@babel/runtime": "^7.18.9", "@material-ui/core": "^4.12.4", - "tslib": "^2.4.0", - "react": "^16.13.0", - "react-dom": "^16.13.0" + "tslib": "^2.4.0" }, "devDependencies": { "@babel/cli": "^7.14.9", diff --git a/packages/sn-auth-react/src/components/authentication-provider.tsx b/packages/sn-auth-react/src/components/authentication-provider.tsx index a84aa2d91..37f7bf2aa 100644 --- a/packages/sn-auth-react/src/components/authentication-provider.tsx +++ b/packages/sn-auth-react/src/components/authentication-provider.tsx @@ -23,8 +23,8 @@ export interface AuthenticationContextState { user: User | null login: (loginRequest: LoginRequest) => Promise externalLogin: () => void - multiFactorLogin: (multiFactorRequest: MultiFactorLoginRequest) => void - forgotPassword: (email: string) => Promise, + multiFactorLogin: (multiFactorRequest: MultiFactorLoginRequest) => Promise + forgotPassword: (email: string, passwordRecoveryUrl?: string) => Promise, passwordRecovery: (token: string, password: string) => Promise, changePassword: (password: string) => Promise logout: () => void @@ -137,7 +137,7 @@ export const AuthenticationProvider = (props: AuthenticationProviderProps) => { }, TOKEN_EXPIRY_THRESHOLD); return () => clearInterval(intervalId); - }, [isRefreshingToken]) + }, [isRefreshingToken]) useEffect(() => { const refreshToken = async () => { @@ -235,12 +235,9 @@ export const AuthenticationProvider = (props: AuthenticationProviderProps) => { const user = await getUserDetailsApiCall(props.authServerUrl, response.accessToken) setUser(user) setUserDetailsStorage(user) - - return response - } - else { - throw new Error() } + + return response } catch (e) { console.log("Error during login.") @@ -259,6 +256,10 @@ export const AuthenticationProvider = (props: AuthenticationProviderProps) => { if (response.accessToken && response.refreshToken) { setAccessAndRefreshToken(response.accessToken, response.refreshToken) + const user = await getUserDetailsApiCall(props.authServerUrl, response.accessToken) + setUser(user) + setUserDetailsStorage(user); + return response; } else { @@ -275,8 +276,8 @@ export const AuthenticationProvider = (props: AuthenticationProviderProps) => { } } - const forgotPassword = async (email: string) => { - await forgotPasswordApiCall(props.authServerUrl, { email }) + const forgotPassword = async (email: string, passwordRecoveryUrl?: string) => { + await forgotPasswordApiCall(props.authServerUrl, { email, passwordRecoveryUrl }) } const passwordRecovery = async (token: string, password: string) => {