@zesty-io/material 0.12.1 → 0.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -15,7 +15,7 @@ export interface SSOButtonGroupProps {
|
|
|
15
15
|
/**
|
|
16
16
|
* Callback invoked upon successful authentication.
|
|
17
17
|
*/
|
|
18
|
-
onSuccess: () => void;
|
|
18
|
+
onSuccess: (message: object) => void;
|
|
19
19
|
/**
|
|
20
20
|
* Callback invoked when an error occurs during authentication.
|
|
21
21
|
* @param error - Description or details of the error.
|
|
@@ -3,10 +3,10 @@ import { Box } from "@mui/material";
|
|
|
3
3
|
import React, { useEffect } from "react";
|
|
4
4
|
import { useSSO } from "../utils/useSSO";
|
|
5
5
|
const SSOButtonGroup = ({ children, sx, authServiceUrl, onSuccess, onError, }) => {
|
|
6
|
-
const [initiate, isAuthenticated, ssoError] = useSSO(authServiceUrl);
|
|
6
|
+
const [initiate, isAuthenticated, ssoError, message] = useSSO(authServiceUrl);
|
|
7
7
|
useEffect(() => {
|
|
8
8
|
if (isAuthenticated && onSuccess) {
|
|
9
|
-
onSuccess();
|
|
9
|
+
onSuccess(message);
|
|
10
10
|
}
|
|
11
11
|
else if (ssoError && onError) {
|
|
12
12
|
onError(ssoError);
|
package/es/utils/useSSO.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare type SSOService = "github" | "google" | "azure";
|
|
2
|
-
export declare const useSSO: (authServiceUrl: string) => readonly [(service: SSOService) => void, boolean, string];
|
|
2
|
+
export declare const useSSO: (authServiceUrl: string) => readonly [(service: SSOService) => void, boolean, string, {}];
|
package/es/utils/useSSO.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { useEffect, useState } from "react";
|
|
2
2
|
let tabWindow = null;
|
|
3
3
|
export const useSSO = (authServiceUrl) => {
|
|
4
|
+
const [message, setMessage] = useState({});
|
|
4
5
|
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
|
5
6
|
const [error, setError] = useState("");
|
|
6
7
|
const receiveMessage = (event) => {
|
|
7
|
-
if (event.origin === authServiceUrl &&
|
|
8
|
-
event.data
|
|
8
|
+
if (event.origin === authServiceUrl && event.data.source === "zesty") {
|
|
9
|
+
setMessage(event.data);
|
|
9
10
|
if (event.data.status === "200") {
|
|
10
11
|
setIsAuthenticated(true);
|
|
11
12
|
}
|
|
@@ -29,5 +30,5 @@ export const useSSO = (authServiceUrl) => {
|
|
|
29
30
|
}
|
|
30
31
|
tabWindow = window.open(`${authServiceUrl}/${service}/login`);
|
|
31
32
|
};
|
|
32
|
-
return [initiate, isAuthenticated, error];
|
|
33
|
+
return [initiate, isAuthenticated, error, message];
|
|
33
34
|
};
|