0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-03-24 22:41:28 -05:00
logto/packages/ui/src/pages/Consent/index.tsx
simeng-li 1c431e7a59
feat(core): apply standard security headers 1/2 (#3590)
* feat(core): add some basic security headers

add some basic security headers

* chore(core): add some comments

add some comments

* chore(core): update the refererPolicy configs

update the refererPolicy configs

* chore(core): update helmet middleware

update helmet middleware

* feat(core): add csp headers to the mainflow and ac http requests 2/2 (#3613)

* feat(core): add csp headers to the mainflow requests

add csp headers to the mainflow requests

* chore(core): add ui and console security headers

add ui and console security headers

* fix(core): remove unused middleware

remove unused middleware

* fix(ui): set terms iframe sandbox

set terms iframe sandbox allow same origin

* fix(core): update security headers middleware

update security headers middleware

* chore(core): add changesets

* chore(core): address rebase conflict

address rebase conflict
2023-04-03 10:24:50 +08:00

55 lines
1.6 KiB
TypeScript

import { conditional } from '@silverhand/essentials';
import { useEffect, useContext, useState } from 'react';
import PageContext from '@/Providers/PageContextProvider/PageContext';
import { consent } from '@/apis/consent';
import { LoadingIcon } from '@/components/LoadingLayer';
import useApi from '@/hooks/use-api';
import useErrorHandler from '@/hooks/use-error-handler';
import { getBrandingLogoUrl } from '@/utils/logo';
import * as styles from './index.module.scss';
const Consent = () => {
const { experienceSettings, theme } = useContext(PageContext);
const handleError = useErrorHandler();
const asyncConsent = useApi(consent);
const { branding, color } = experienceSettings ?? {};
const brandingLogo = conditional(
branding &&
color &&
getBrandingLogoUrl({ theme, branding, isDarkModeEnabled: color.isDarkModeEnabled })
);
const [loading, setLoading] = useState(true);
useEffect(() => {
(async () => {
const [error, result] = await asyncConsent();
setLoading(false);
if (error) {
await handleError(error);
return;
}
if (result?.redirectTo) {
window.location.replace(result.redirectTo);
}
})();
}, [asyncConsent, handleError]);
return (
<div className={styles.viewBox}>
<div className={styles.container}>
{brandingLogo && (
<img alt="logo" className={styles.img} src={brandingLogo} crossOrigin="anonymous" />
)}
<div className={styles.loadingWrapper}>{loading && <LoadingIcon />}</div>
</div>
</div>
);
};
export default Consent;