Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions src/components/auth/auth_initializer/AuthInitializer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ import { AuthProviderFactory } from "@logora/debate/auth/providers";
import { authTokenHandler, useAuthActions } from "@logora/debate/auth/use_auth";
import { useAuthInterceptor } from "@logora/debate/auth/use_auth";
import { httpClient } from "@logora/debate/data/axios_client";
import { useConfig } from "@logora/debate/data/config_provider";
import { UpdateUserInfoModal } from "@logora/debate/user/update_user_info_modal";
import { useAuthRequired } from "@logora/debate/hooks/use_auth_required";
import { useEffect } from "react";
import React, { useState, useEffect } from "react";

export const AuthInitializer = ({ authUrl, authType, provider, assertion }) => {
const tokenKey = "logora_user_token";
const config = useConfig();
useAuthInterceptor(httpClient, authUrl, tokenKey);

const [pendingAuth, setPendingAuth] = useState(null);

const { getToken, removeToken } = authTokenHandler(
httpClient,
authUrl,
Expand Down Expand Up @@ -60,16 +65,44 @@ export const AuthInitializer = ({ authUrl, authType, provider, assertion }) => {
if (authProvider.shouldInitAuth()) {
const authParams = authProvider.getAuthorizationParams();
if (authParams) {
loginUser(authParams);
if (config.auth?.hideCgu !== true) {
setPendingAuth(authParams);
} else {
loginUser(authParams);
}
}
} else {
logoutUser();
}
};

const handleConsentConfirmed = (consentedAuthParams) => {
loginUser(consentedAuthParams);
setPendingAuth(null);
};

const getAuthProvider = () => {
return AuthProviderFactory.create(authType, provider, assertion);
};

return null;
return (
<>
{pendingAuth && (
<UpdateUserInfoModal
pendingAuth={pendingAuth}
onConsentConfirmed={handleConsentConfirmed}
showTerms={true}
showEmailConsent={config.auth?.showEmailConsent}
termsUrl={
config.provider?.cguUrl ||
"https://www.logora.com/blog-posts/cgu"
}
privacyUrl={
config.provider?.privacyUrl ||
"https://www.logora.com/blog-posts/privacy-policy"
}
/>
)}
</>
);
};
7 changes: 1 addition & 6 deletions src/components/auth/social_auth_form/SocialAuthForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import { FacebookLoginButton } from "@logora/debate/auth/facebook_login_button";
import { GoogleLoginButton } from "@logora/debate/auth/google_login_button";
import { LoginForm } from "@logora/debate/auth/login_form";
import { SignupForm } from "@logora/debate/auth/signup_form";
import { EMAIL_CONSENT_STORAGE_KEY } from "@logora/debate/auth/use_auth";
import { Icon } from "@logora/debate/icons/icon";
import { Toggle } from "@logora/debate/input/toggle";
import useSessionStorageState from "@rooks/use-sessionstorage-state";
import React, { useState } from "react";
import { FormattedMessage, useIntl } from "react-intl";
import styles from "./SocialAuthForm.module.scss";
Expand All @@ -27,10 +25,7 @@ export const SocialAuthForm = ({
!(lastStep === "LOGIN" || lastStep === "SIGNUP"),
);
const [loginStep, setLoginStep] = useState(lastStep !== "SIGNUP");
const [emailConsent, setEmailConsent] = useSessionStorageState(
EMAIL_CONSENT_STORAGE_KEY,
false,
);
const [emailConsent, setEmailConsent] = useState(false);
const intl = useIntl();

const handleSignUp = (
Expand Down
1 change: 1 addition & 0 deletions src/components/auth/use_auth/useAuthActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const useAuthActions = (httpClient, authUrl, tokenKey) => {
setIsLoggingIn(false);
setCurrentUser({});
removeToken();
sessionStorage.removeItem(EMAIL_CONSENT_STORAGE_KEY);
dispatchLogoutEvent();
};

Expand Down
Loading