Merge branch 'feature/login-nextjs' of github.com:ONLYOFFICE/DocSpace-client into feature/login-nextjs
This commit is contained in:
commit
4513a4a2c6
@ -24,7 +24,7 @@
|
||||
// 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 { redirect } from "next/navigation";
|
||||
import { permanentRedirect, redirect } from "next/navigation";
|
||||
import { cookies, headers } from "next/headers";
|
||||
|
||||
import { Toast } from "@docspace/shared/components/toast";
|
||||
@ -52,13 +52,13 @@ export default async function RootLayout({
|
||||
|
||||
const timers = { isAuth: 0, otherOperations: 0 };
|
||||
|
||||
const startIsAuthDate = new Date();
|
||||
const cookieStore = cookies();
|
||||
|
||||
const isAuth = await checkIsAuthenticated();
|
||||
const systemTheme = cookieStore.get(SYSTEM_THEME_KEY);
|
||||
|
||||
timers.isAuth = new Date().getTime() - startIsAuthDate.getTime();
|
||||
let redirectUrl = "";
|
||||
|
||||
if (isAuth) redirect(`${baseUrl}`);
|
||||
const api_host = process.env.API_HOST?.trim();
|
||||
|
||||
const startOtherOperationsDate = new Date();
|
||||
|
||||
@ -70,7 +70,7 @@ export default async function RootLayout({
|
||||
timers.otherOperations =
|
||||
new Date().getTime() - startOtherOperationsDate.getTime();
|
||||
|
||||
if (settings === "access-restricted") redirect(`${baseUrl}/${settings}`);
|
||||
if (settings === "access-restricted") redirectUrl = `/${settings}`;
|
||||
|
||||
if (settings === "portal-not-found") {
|
||||
const config = await (
|
||||
@ -86,27 +86,27 @@ export default async function RootLayout({
|
||||
|
||||
url.searchParams.append("url", host ?? "");
|
||||
|
||||
redirect(url.toString());
|
||||
redirectUrl = url.toString();
|
||||
}
|
||||
|
||||
if (settings?.wizardToken) {
|
||||
redirect(`${baseUrl}/wizard`);
|
||||
if (typeof settings !== "string" && settings?.wizardToken) {
|
||||
redirectUrl = `wizard`;
|
||||
}
|
||||
|
||||
if (settings?.tenantStatus === TenantStatus.PortalRestore) {
|
||||
redirect(`${baseUrl}/preparation-portal`);
|
||||
if (
|
||||
typeof settings !== "string" &&
|
||||
settings?.tenantStatus === TenantStatus.PortalRestore
|
||||
) {
|
||||
redirectUrl = `preparation-portal`;
|
||||
}
|
||||
|
||||
if (settings?.tenantStatus === TenantStatus.PortalDeactivate) {
|
||||
redirect(`${baseUrl}/unavailable`);
|
||||
if (
|
||||
typeof settings !== "string" &&
|
||||
settings?.tenantStatus === TenantStatus.PortalDeactivate
|
||||
) {
|
||||
redirectUrl = `unavailable`;
|
||||
}
|
||||
|
||||
const cookieStore = cookies();
|
||||
|
||||
const systemTheme = cookieStore.get(SYSTEM_THEME_KEY);
|
||||
|
||||
const api_host = process.env.API_HOST?.trim();
|
||||
|
||||
return (
|
||||
<html lang="en" translate="no">
|
||||
<head>
|
||||
@ -123,14 +123,15 @@ export default async function RootLayout({
|
||||
<StyledComponentsRegistry>
|
||||
<Providers
|
||||
value={{
|
||||
settings,
|
||||
settings: typeof settings !== "string" ? settings : undefined,
|
||||
colorTheme,
|
||||
systemTheme: systemTheme?.value as ThemeKeys,
|
||||
}}
|
||||
timers={timers}
|
||||
api_host={api_host}
|
||||
redirectURL={redirectUrl}
|
||||
>
|
||||
<SimpleNav />
|
||||
<SimpleNav systemTheme={systemTheme?.value as ThemeKeys} />
|
||||
<Toast isSSR />
|
||||
{children}
|
||||
</Providers>
|
||||
|
@ -26,11 +26,14 @@
|
||||
|
||||
"use server";
|
||||
import { redirect } from "next/navigation";
|
||||
import { headers } from "next/headers";
|
||||
import { cookies, headers } from "next/headers";
|
||||
|
||||
import { getBaseUrl } from "@docspace/shared/utils/next-ssr-helper";
|
||||
import { getBgPattern } from "@docspace/shared/utils/common";
|
||||
|
||||
import { SYSTEM_THEME_KEY } from "@docspace/shared/constants";
|
||||
import { ThemeKeys } from "@docspace/shared/enums";
|
||||
|
||||
import Login from "@/components/Login";
|
||||
import { LoginFormWrapper } from "@/components/Login/Login.styled";
|
||||
import {
|
||||
@ -48,11 +51,6 @@ async function Page({
|
||||
searchParams: { [key: string]: string };
|
||||
}) {
|
||||
const timers = { isAuth: 0, otherOperations: 0 };
|
||||
const startIsAuthDate = new Date();
|
||||
|
||||
const isAuth = await checkIsAuthenticated();
|
||||
|
||||
timers.isAuth = new Date().getTime() - startIsAuthDate.getTime();
|
||||
|
||||
const startOtherOperationsDate = new Date();
|
||||
|
||||
@ -96,6 +94,10 @@ async function Page({
|
||||
|
||||
const bgPattern = getBgPattern(colorTheme?.selected);
|
||||
|
||||
const cookieStore = cookies();
|
||||
|
||||
const systemTheme = cookieStore.get(SYSTEM_THEME_KEY);
|
||||
|
||||
return (
|
||||
<LoginFormWrapper id="login-page" bgPattern={bgPattern}>
|
||||
<div className="bg-cover" />
|
||||
@ -105,7 +107,8 @@ async function Page({
|
||||
settings={settings}
|
||||
thirdPartyProvider={thirdParty}
|
||||
ssoSettings={ssoSettings}
|
||||
isAuthenticated={isAuth}
|
||||
isAuthenticated={false}
|
||||
systemTheme={systemTheme?.value as ThemeKeys}
|
||||
timers={timers}
|
||||
/>
|
||||
</LoginFormWrapper>
|
||||
|
@ -30,7 +30,7 @@ import { useState, useCallback, useEffect } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useTheme } from "styled-components";
|
||||
|
||||
import { WhiteLabelLogoType } from "@docspace/shared/enums";
|
||||
import { ThemeKeys, WhiteLabelLogoType } from "@docspace/shared/enums";
|
||||
import { PROVIDERS_DATA } from "@docspace/shared/constants";
|
||||
import {
|
||||
getBgPattern,
|
||||
@ -64,6 +64,7 @@ const Login = ({
|
||||
thirdPartyProvider,
|
||||
isAuthenticated,
|
||||
timers,
|
||||
systemTheme,
|
||||
}: LoginProps) => {
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
@ -75,7 +76,8 @@ const Login = ({
|
||||
type: "",
|
||||
});
|
||||
|
||||
const theme = useTheme();
|
||||
console.log("api res", settings, capabilities, thirdPartyProvider);
|
||||
|
||||
const { t } = useTranslation(["Login", "Common"]);
|
||||
|
||||
const {
|
||||
@ -183,7 +185,9 @@ const Login = ({
|
||||
[],
|
||||
);
|
||||
|
||||
const logoUrl = getLogoUrl(WhiteLabelLogoType.LoginPage, !theme?.isBase);
|
||||
const isDark = systemTheme === ThemeKeys.DarkStr;
|
||||
|
||||
const logoUrl = getLogoUrl(WhiteLabelLogoType.LoginPage, isDark);
|
||||
|
||||
const ssoProps = ssoExists()
|
||||
? {
|
||||
@ -195,6 +199,8 @@ const Login = ({
|
||||
|
||||
const isRegisterContainerVisible = settings?.enabledJoin;
|
||||
|
||||
console.log("settings", settings);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Scrollbar id="customScrollBar">
|
||||
|
@ -28,12 +28,11 @@
|
||||
"use client";
|
||||
|
||||
import React from "react";
|
||||
import styled, { useTheme } from "styled-components";
|
||||
import styled from "styled-components";
|
||||
|
||||
import { mobile } from "@docspace/shared/utils/device";
|
||||
import { getLogoFromPath, getLogoUrl } from "@docspace/shared/utils/common";
|
||||
import { Base } from "@docspace/shared/themes";
|
||||
import { TWhiteLabel } from "@docspace/shared/utils/whiteLabelHelper";
|
||||
import { getLogoUrl } from "@docspace/shared/utils/common";
|
||||
import { Base, Dark } from "@docspace/shared/themes";
|
||||
import { ThemeKeys, WhiteLabelLogoType } from "@docspace/shared/enums";
|
||||
|
||||
const StyledSimpleNav = styled.div<{ isError: boolean }>`
|
||||
@ -56,20 +55,25 @@ const StyledSimpleNav = styled.div<{ isError: boolean }>`
|
||||
|
||||
StyledSimpleNav.defaultProps = { theme: Base };
|
||||
|
||||
interface SimpleNavProps {}
|
||||
interface SimpleNavProps {
|
||||
systemTheme: ThemeKeys;
|
||||
}
|
||||
|
||||
const SimpleNav = ({}: SimpleNavProps) => {
|
||||
const theme = useTheme();
|
||||
const SimpleNav = ({ systemTheme }: SimpleNavProps) => {
|
||||
const isDark = systemTheme === ThemeKeys.DarkStr;
|
||||
const logoUrl = getLogoUrl(WhiteLabelLogoType.LightSmall, isDark);
|
||||
|
||||
const logoUrl = getLogoUrl(WhiteLabelLogoType.LightSmall, !theme?.isBase);
|
||||
|
||||
const isError =
|
||||
typeof window !== "undefined"
|
||||
? window?.location?.pathname === "/login/error"
|
||||
: false;
|
||||
const isError = false;
|
||||
typeof window !== "undefined"
|
||||
? window?.location?.pathname === "/login/error"
|
||||
: false;
|
||||
|
||||
return (
|
||||
<StyledSimpleNav id="login-header" isError={isError}>
|
||||
<StyledSimpleNav
|
||||
id="login-header"
|
||||
isError={isError}
|
||||
theme={isDark ? Dark : Base}
|
||||
>
|
||||
<img src={logoUrl} alt="logo-url" />
|
||||
</StyledSimpleNav>
|
||||
);
|
||||
|
@ -29,10 +29,18 @@ import type { NextRequest } from "next/server";
|
||||
|
||||
// This function can be marked `async` if using `await` inside
|
||||
export function middleware(request: NextRequest) {
|
||||
return NextResponse.json({ status: "healthy" }, { status: 200 });
|
||||
if (request.url === "health")
|
||||
return NextResponse.json({ status: "healthy" }, { status: 200 });
|
||||
|
||||
const isAuth = !!request.cookies.get("asc_auth_key")?.value;
|
||||
|
||||
const url = request.nextUrl.clone();
|
||||
url.pathname = "/";
|
||||
|
||||
if (isAuth) return NextResponse.redirect("http://192.168.0.18");
|
||||
}
|
||||
|
||||
// See "Matching Paths" below to learn more
|
||||
export const config = {
|
||||
matcher: "/health",
|
||||
matcher: ["/health", "/"],
|
||||
};
|
||||
|
@ -49,9 +49,11 @@ export const Providers = ({
|
||||
value,
|
||||
timers,
|
||||
api_host,
|
||||
redirectURL,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
value: TDataContext;
|
||||
redirectURL: string;
|
||||
}) => {
|
||||
const firebaseHelper = new FirebaseHelper(
|
||||
value.settings?.firebase ?? ({} as TFirebaseSettings),
|
||||
@ -62,6 +64,10 @@ export const Providers = ({
|
||||
console.log("API_HOST: ", api_host);
|
||||
}, [api_host, timers]);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (redirectURL) window.location.replace("/");
|
||||
}, [redirectURL]);
|
||||
|
||||
const { currentDeviceType } = useDeviceType();
|
||||
|
||||
const { i18n } = useI18N({
|
||||
|
@ -57,6 +57,7 @@ export type LoginProps = {
|
||||
capabilities?: TCapabilities;
|
||||
thirdPartyProvider?: TThirdPartyProvider[];
|
||||
ssoSettings?: TGetSsoSettings;
|
||||
systemTheme?: ThemeKeys;
|
||||
};
|
||||
|
||||
export type RegisterProps = {
|
||||
|
Loading…
Reference in New Issue
Block a user