Login:OAuth2: fix consent change user

This commit is contained in:
Timofey Boyko 2023-11-14 11:38:44 +03:00
parent 6c78635489
commit 280400f0a2
3 changed files with 29 additions and 5 deletions

View File

@ -76,6 +76,9 @@ const Login: React.FC<ILoginProps> = ({
oauth?.client || ({} as IClientProps)
);
const [self, setSelf] = useState(oauth?.self || ({} as ISelf));
const [hashSettings, setHashSettings] = useState<null | PasswordHashType>(
null
);
const {
enabledJoin,
@ -237,6 +240,8 @@ const Login: React.FC<ILoginProps> = ({
if (!mounted) return <></>;
if (isRestoringPortal) return <></>;
console.log(portalSettings);
return (
<LoginFormWrapper
id="login-page"
@ -260,6 +265,8 @@ const Login: React.FC<ILoginProps> = ({
<Consent
oauth={{ ...oauth, scopes, client: oauthClient, self }}
theme={theme}
hashSettings={portalSettings?.passwordHash || hashSettings}
setHashSettings={setHashSettings}
setIsConsentScreen={setIsConsentPage}
/>
) : (
@ -296,7 +303,7 @@ const Login: React.FC<ILoginProps> = ({
recaptchaPublicKey={portalSettings?.recaptchaPublicKey}
isDesktop={!!isDesktopEditor}
isLoading={isLoading}
hashSettings={portalSettings?.passwordHash}
hashSettings={portalSettings?.passwordHash || hashSettings}
setIsLoading={setIsLoading}
openRecoverDialog={openRecoverDialog}
match={match}

View File

@ -69,10 +69,18 @@ StyledFormWrapper.defaultProps = { theme: Base };
interface IConsentProps {
oauth: IOAuthState;
theme: IUserTheme;
hashSettings: null | PasswordHashType;
setHashSettings: (hashSettings: PasswordHashType | null) => void;
setIsConsentScreen: (value: boolean) => void;
}
const Consent = ({ oauth, theme, setIsConsentScreen }: IConsentProps) => {
const Consent = ({
oauth,
theme,
setIsConsentScreen,
hashSettings,
setHashSettings,
}: IConsentProps) => {
const navigate = useNavigate();
const location = useLocation();
@ -107,8 +115,16 @@ const Consent = ({ oauth, theme, setIsConsentScreen }: IConsentProps) => {
window.location.href = oauth.client.websiteUrl;
};
const onChangeUserClick = () => {
api.user.logout();
const onChangeUserClick = async () => {
await api.user.logout();
if (!hashSettings) {
const portalSettings = await api.settings.getSettings();
console.log(portalSettings);
setHashSettings(portalSettings.passwordHash);
}
setIsConsentScreen(false);
navigate(`/login/${location.search}`);
};

View File

@ -37,7 +37,7 @@ import { IClientProps, IScope } from "@docspace/common/utils/oauth/interfaces";
interface ILoginFormProps {
isLoading: boolean;
setIsLoading: (isLoading: boolean) => void;
hashSettings: PasswordHashType;
hashSettings: PasswordHashType | null;
isDesktop: boolean;
match: MatchType;
openRecoverDialog: () => void;
@ -221,6 +221,7 @@ const LoginForm: React.FC<ILoginFormProps> = ({
setIsLoading(true);
console.log(pass, hashSettings);
const hash = createPasswordHash(pass, hashSettings);
isDesktop && checkPwd();