mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Check setup step and redirect to /setup if needed
This commit is contained in:
parent
cdf482ac4a
commit
d178b78e86
@ -34,6 +34,8 @@ import {
|
||||
getTokenWJ,
|
||||
setSsrApiUrl,
|
||||
useUserTheme,
|
||||
SetupStep,
|
||||
ServerInfo,
|
||||
} from "@kyoo/models";
|
||||
import { getCurrentAccount, readCookie, updateAccount } from "@kyoo/models/src/account-internal";
|
||||
import {
|
||||
@ -56,6 +58,8 @@ import { Tooltip } from "react-tooltip";
|
||||
import superjson from "superjson";
|
||||
import { StyleRegistryProvider, useMobileHover, useStyleRegistry, useTheme } from "yoshiki/web";
|
||||
import { withTranslations } from "../i18n";
|
||||
import { redirect } from "next/navigation";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
const font = Poppins({ weight: ["300", "400", "900"], subsets: ["latin"], display: "swap" });
|
||||
|
||||
@ -214,22 +218,36 @@ App.getInitialProps = async (ctx: AppContext) => {
|
||||
|
||||
setSsrApiUrl();
|
||||
|
||||
appProps.pageProps.theme = readCookie(ctx.ctx.req?.headers.cookie, "theme") ?? "auto";
|
||||
|
||||
const account = readCookie(ctx.ctx.req?.headers.cookie, "account", AccountP);
|
||||
if (account) urls.push({ path: ["auth", "me"], parser: UserP });
|
||||
const [authToken, token, error] = await getTokenWJ(account);
|
||||
if (error) appProps.pageProps.ssrError = error;
|
||||
else {
|
||||
const client = (await fetchQuery(urls, authToken))!;
|
||||
appProps.pageProps.queryState = dehydrate(client);
|
||||
if (account) {
|
||||
appProps.pageProps.token = token;
|
||||
appProps.pageProps.account = {
|
||||
...client.getQueryData(["auth", "me"]),
|
||||
...account,
|
||||
};
|
||||
}
|
||||
const client = (await fetchQuery(urls, authToken))!;
|
||||
appProps.pageProps.queryState = dehydrate(client);
|
||||
if (account) {
|
||||
appProps.pageProps.token = token;
|
||||
appProps.pageProps.account = {
|
||||
...client.getQueryData(["auth", "me"]),
|
||||
...account,
|
||||
};
|
||||
}
|
||||
|
||||
const info = client.getQueryData<ServerInfo>(["info"]);
|
||||
if (
|
||||
info!.setupStatus !== SetupStep.Done &&
|
||||
!(
|
||||
(ctx.router.route === "/setup" && ctx.router.query.step === info!.setupStatus) ||
|
||||
ctx.router.route === "/register" ||
|
||||
ctx.router.route === "/login" ||
|
||||
ctx.router.route === "/settings"
|
||||
)
|
||||
) {
|
||||
ctx.ctx.res!.writeHead(307, { Location: `/setup?step=${info!.setupStatus}` });
|
||||
ctx.ctx.res!.end();
|
||||
return {} as any;
|
||||
}
|
||||
appProps.pageProps.theme = readCookie(ctx.ctx.req?.headers.cookie, "theme") ?? "auto";
|
||||
} catch (e) {
|
||||
console.error("SSR error, disabling it.");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user