feat: simple impl
This commit is contained in:
@ -1,15 +1,17 @@
|
||||
"use client";
|
||||
|
||||
import { FC, useEffect, useState } from "react";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
import { useSelector } from "react-redux";
|
||||
import { Button, Text } from "@mantine/core";
|
||||
import { Auth } from "@/client";
|
||||
import SCOPES from "@/constants/scopes";
|
||||
import { Scopes } from "@/enums/Scopes";
|
||||
import { notifications } from "@/lib/notifications";
|
||||
import { RootState } from "@/lib/store";
|
||||
import { AuthService } from "@/mocks/authService";
|
||||
|
||||
const ConsentButton: FC = () => {
|
||||
const searchParams = useSearchParams();
|
||||
const auth = useSelector((state: RootState) => state.auth);
|
||||
const [clientName, setClientName] = useState<string>(Scopes.UNDEFINED);
|
||||
const [serviceRequiredAccess, setServiceRequiredAccess] =
|
||||
@ -25,18 +27,17 @@ const ConsentButton: FC = () => {
|
||||
};
|
||||
|
||||
const requestConsent = () => {
|
||||
if (!auth.loginChallenge || auth.scope.length === 0) return;
|
||||
|
||||
new AuthService()
|
||||
.requestConsent(auth.loginChallenge)
|
||||
.then(response => response.data)
|
||||
.then(({ clientName }) => {
|
||||
setClientName(clientName);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
notifications.error({ message: error.toString() });
|
||||
});
|
||||
// if (!auth.loginChallenge || auth.scope.length === 0) return;
|
||||
// new AuthService()
|
||||
// .requestConsent(auth.loginChallenge)
|
||||
// .then(response => response.data)
|
||||
// .then(({ clientName }) => {
|
||||
// setClientName(clientName);
|
||||
// })
|
||||
// .catch(error => {
|
||||
// console.error(error);
|
||||
// notifications.error({ message: error.toString() });
|
||||
// });
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
@ -45,18 +46,40 @@ const ConsentButton: FC = () => {
|
||||
}, []);
|
||||
|
||||
const confirmAccess = () => {
|
||||
if (!auth.loginChallenge) return;
|
||||
|
||||
new AuthService()
|
||||
.approveConsent(auth.loginChallenge)
|
||||
const consentChallenge = searchParams.get("consent_challenge");
|
||||
if (!consentChallenge) {
|
||||
console.error("Consent challenge is missing in the URL");
|
||||
return;
|
||||
}
|
||||
Auth.postAuthConsentAccept({
|
||||
body: { consent_challenge: consentChallenge },
|
||||
})
|
||||
.then(response => response.data)
|
||||
.then(({ redirectUrl }) => {
|
||||
window.location.href = redirectUrl;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
notifications.error({ message: error.toString() });
|
||||
.then(response => {
|
||||
if (!response) {
|
||||
console.error("Response is empty");
|
||||
return;
|
||||
}
|
||||
const { redirect_url, ok, message } = response;
|
||||
notifications.guess(ok, { message });
|
||||
|
||||
if (redirect_url) {
|
||||
window.location.href = redirect_url;
|
||||
} else {
|
||||
console.error("Redirect URL is missing in the response");
|
||||
}
|
||||
});
|
||||
// if (!auth.loginChallenge) return;
|
||||
// new AuthService()
|
||||
// .approveConsent(auth.loginChallenge)
|
||||
// .then(response => response.data)
|
||||
// .then(({ redirectUrl }) => {
|
||||
// window.location.href = redirectUrl;
|
||||
// })
|
||||
// .catch(error => {
|
||||
// console.error(error);
|
||||
// notifications.error({ message: error.toString() });
|
||||
// });
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user