Login: fix oauth pages

This commit is contained in:
Timofey Boyko 2024-08-23 10:42:14 +03:00
parent 5366f41f37
commit f9a123d42d
4 changed files with 94 additions and 43 deletions

View File

@ -23,11 +23,20 @@
// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
import { cookies } from "next/headers";
import { IClientProps } from "@docspace/shared/utils/oauth/types";
import { ColorTheme, ThemeId } from "@docspace/shared/components/color-theme";
import { LANGUAGE } from "@docspace/shared/constants";
import Consent from "@/components/Consent";
import { getOAuthClient, getScopeList, getUser } from "@/utils/actions";
import {
getOAuthClient,
getScopeList,
getSettings,
getUser,
} from "@/utils/actions";
import { GreetingLoginContainer } from "@/components/GreetingContainer";
async function Page({
searchParams,
@ -35,17 +44,45 @@ async function Page({
searchParams: { [key: string]: string };
}) {
const clientId = searchParams.clientId ?? searchParams.client_id;
const [client, scopes, user] = await Promise.all([
const [client, scopes, user, settings] = await Promise.all([
getOAuthClient(clientId),
getScopeList(),
getUser(),
getSettings(),
]);
if (!client || (client && !("clientId" in client)) || !scopes || !user)
return "";
const isRegisterContainerVisible =
typeof settings === "string" ? undefined : settings?.enabledJoin;
const settingsCulture =
typeof settings === "string" ? undefined : settings?.culture;
const culture = cookies().get(LANGUAGE)?.value ?? settingsCulture;
return (
<Consent client={client as IClientProps} scopes={scopes} user={user} />
<>
{settings && typeof settings !== "string" && (
<ColorTheme
themeId={ThemeId.LinkForgotPassword}
isRegisterContainerVisible={isRegisterContainerVisible}
>
<>
<GreetingLoginContainer
greetingSettings={settings?.greetingSettings}
culture={culture}
/>
<Consent
client={client as IClientProps}
scopes={scopes}
user={user}
/>
</>
</ColorTheme>
)}
</>
);
}

View File

@ -106,36 +106,25 @@ async function Page({
ldapDomain={capabilities?.ldapDomain}
ldapEnabled={capabilities?.ldapEnabled || false}
/>
<ThirdParty
thirdParty={thirdParty}
capabilities={capabilities}
ssoExists={ssoExists}
ssoUrl={ssoUrl}
hideAuthPage={hideAuthPage}
oauthDataExists={oauthDataExists}
/>
{!clientId && (
<ThirdParty
thirdParty={thirdParty}
capabilities={capabilities}
ssoExists={ssoExists}
ssoUrl={ssoUrl}
hideAuthPage={hideAuthPage}
oauthDataExists={oauthDataExists}
/>
)}
{settings.enableAdmMess && <RecoverAccess />}
{settings.enabledJoin && (
<>
<Register
id="login_register"
enabledJoin
trustedDomains={settings.trustedDomains}
trustedDomainsType={settings.trustedDomainsType}
isAuthenticated={false}
/>
{!clientId && <ThirdParty />}
{settings.enableAdmMess && <RecoverAccess />}
{settings.enabledJoin && (
<Register
id="login_register"
enabledJoin
trustedDomains={settings.trustedDomains}
trustedDomainsType={settings.trustedDomainsType}
isAuthenticated={false}
/>
)}
</>
<Register
id="login_register"
enabledJoin
trustedDomains={settings.trustedDomains}
trustedDomainsType={settings.trustedDomainsType}
isAuthenticated={false}
/>
)}
</Login>
</FormWrapper>

View File

@ -1,5 +1,10 @@
import { cookies } from "next/headers";
import { GreetingLoginContainer } from "@/components/GreetingContainer";
import TenantList from "@/components/TenantList";
import { getSettings } from "@/utils/actions";
import { ColorTheme, ThemeId } from "@docspace/shared/components/color-theme";
import { LANGUAGE } from "@docspace/shared/constants";
export default async function Page({
searchParams,
@ -11,13 +16,33 @@ export default async function Page({
const { portals } = JSON.parse(searchParams.portals);
const clientId = searchParams.clientId;
if (typeof settings !== "object") return;
const isRegisterContainerVisible =
typeof settings === "string" ? undefined : settings?.enabledJoin;
const settingsCulture =
typeof settings === "string" ? undefined : settings?.culture;
const culture = cookies().get(LANGUAGE)?.value ?? settingsCulture;
return (
<TenantList
portals={portals}
clientId={clientId}
baseDomain={settings.baseDomain}
/>
<>
{settings && typeof settings !== "string" && (
<ColorTheme
themeId={ThemeId.LinkForgotPassword}
isRegisterContainerVisible={isRegisterContainerVisible}
>
<>
<GreetingLoginContainer
greetingSettings={settings?.greetingSettings}
culture={culture}
/>
<TenantList
portals={portals}
clientId={clientId}
baseDomain={settings.baseDomain}
/>
</>
</ColorTheme>
)}
</>
);
}

View File

@ -283,11 +283,11 @@ const LoginForm = ({
PasswordHash: hash,
});
if (portals.length === 1) {
window.open(`${portals[0].portalLink}`, "_self");
// if (portals.length === 1) {
// window.open(`${portals[0].portalLink}`, "_self");
return;
}
// return;
// }
const searchParams = new URLSearchParams();
@ -319,7 +319,7 @@ const LoginForm = ({
}
return res;
})
.then((res: string | object) => {
.then((res?: string | object) => {
const isConfirm = typeof res === "string" && res.includes("confirm");
const redirectPath =
referenceUrl || sessionStorage.getItem("referenceUrl");
@ -439,7 +439,7 @@ const LoginForm = ({
return (
<form className="auth-form-container">
{!emailFromInvitation && (
{!emailFromInvitation && !client && (
<Text fontSize="16px" fontWeight="600" className="sign-in-subtitle">
{t("Common:LoginButton")}
</Text>