Skip to content

Commit c94ca06

Browse files
committed
update to support callback
1 parent 1074078 commit c94ca06

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

packages/react-auth/CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,24 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## 0.0.21 - 2025-11-25
9+
10+
### Changed
11+
12+
- Support onRedirectCallback parameter
13+
814
## 0.0.20 - 2025-11-19
915

1016
### Changed
1117

1218
- Upgraded @pangeacyber/vanilla-js auth client version
1319

20+
## 0.0.19 - 2025-11-19
21+
22+
### Changed
23+
24+
- Upgraded @pangeacyber/vanilla-js auth client version
25+
1426
### Added
1527

1628
- Switch usePathApi to apiPathPrefix path parameter to AuthConfig

packages/react-auth/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@pangeacyber/react-auth",
33
"description": "Pangea auth provider React component",
4-
"version": "0.0.20",
4+
"version": "0.0.21",
55
"type": "commonjs",
66
"source": "src/index.ts",
77
"main": "dist/index.cjs",

packages/react-auth/src/AuthProvider/index.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ export interface AuthProviderProps {
8181
*/
8282
redirectPathname?: string;
8383

84+
/**
85+
* When passed in, AuthProvider will call this function when needing to redirect
86+
* @example "/docs/""
87+
*/
88+
onRedirectCallback?: (url: string) => void;
89+
8490
/**
8591
* When set to true users will be redirected to the hosted page on logout.
8692
*
@@ -152,6 +158,7 @@ export const AuthProvider: FC<AuthProviderProps> = ({
152158
cookieOptions = { useCookie: false },
153159
redirectUri,
154160
redirectPathname,
161+
onRedirectCallback,
155162
redirectOnLogout = false,
156163
useStrictStateCheck = true,
157164
passAuthMethod = false,
@@ -378,7 +385,11 @@ export const AuthProvider: FC<AuthProviderProps> = ({
378385
const redirectTo = loginURL;
379386
const url = queryParams ? `${redirectTo}?${queryParams}` : redirectTo;
380387

381-
window.location.replace(url);
388+
if (onRedirectCallback) {
389+
onRedirectCallback(url);
390+
} else {
391+
window.location.replace(url);
392+
}
382393
};
383394

384395
const logout = useCallback(async () => {
@@ -400,7 +411,11 @@ export const AuthProvider: FC<AuthProviderProps> = ({
400411
const url = `${logoutURL}?${toUrlEncoded(query)}`;
401412

402413
setLoggedOut();
403-
window.location.replace(url);
414+
if (onRedirectCallback) {
415+
onRedirectCallback(url);
416+
} else {
417+
window.location.replace(url);
418+
}
404419
}
405420
// call the logout endpoint
406421
else {

0 commit comments

Comments
 (0)