diff --git a/back/src/Kyoo.Authentication/Models/DTO/ServerInfo.cs b/back/src/Kyoo.Authentication/Models/DTO/ServerInfo.cs index bfb3dbd2..8c2e5cce 100644 --- a/back/src/Kyoo.Authentication/Models/DTO/ServerInfo.cs +++ b/back/src/Kyoo.Authentication/Models/DTO/ServerInfo.cs @@ -27,6 +27,11 @@ public class ServerInfo /// public Dictionary Oidc { get; set; } + /// + /// The url to reach the homepage of kyoo (add /api for the api). + /// + public string PublicUrl { get; set; } + /// /// True if guest accounts are allowed on this instance. /// diff --git a/back/src/Kyoo.Authentication/Views/InfoApi.cs b/back/src/Kyoo.Authentication/Views/InfoApi.cs index 93065198..495cc71b 100644 --- a/back/src/Kyoo.Authentication/Views/InfoApi.cs +++ b/back/src/Kyoo.Authentication/Views/InfoApi.cs @@ -40,6 +40,7 @@ public class InfoApi(PermissionOption options) : ControllerBase { AllowGuests = options.Default.Any(), GuestPermissions = options.Default.ToList(), + PublicUrl = options.PublicUrl, Oidc = options .OIDC.Select(x => new KeyValuePair( x.Key, diff --git a/front/apps/web/src/pages/_app.tsx b/front/apps/web/src/pages/_app.tsx index 7043cc5f..640f3220 100755 --- a/front/apps/web/src/pages/_app.tsx +++ b/front/apps/web/src/pages/_app.tsx @@ -222,14 +222,14 @@ App.getInitialProps = async (ctx: AppContext) => { else { const client = (await fetchQuery(urls, authToken))!; appProps.pageProps.queryState = dehydrate(client); - appProps.pageProps.token = token; - appProps.pageProps.account = { - ...client.getQueryData(["auth", "me"]), - ...account, - }; + if (account) { + appProps.pageProps.token = token; + appProps.pageProps.account = { + ...client.getQueryData(["auth", "me"]), + ...account, + }; + } } - // TODO: return account from /auth/me and not the one from cookies, - // do not forget to leave apiUrl and selected intact appProps.pageProps.theme = readCookie(ctx.ctx.req?.headers.cookie, "theme") ?? "auto"; return { pageProps: superjson.serialize(appProps.pageProps) }; diff --git a/front/packages/models/src/query.tsx b/front/packages/models/src/query.tsx index 7ed0f64b..1067e374 100644 --- a/front/packages/models/src/query.tsx +++ b/front/packages/models/src/query.tsx @@ -20,12 +20,10 @@ import { ComponentType, ReactElement } from "react"; import { - dehydrate, QueryClient, QueryFunctionContext, useInfiniteQuery, useQuery, - useQueryClient, } from "@tanstack/react-query"; import { z } from "zod"; import { KyooErrors } from "./kyoo-errors"; diff --git a/front/packages/models/src/resources/server-info.ts b/front/packages/models/src/resources/server-info.ts index 00b84c0f..7266e89d 100644 --- a/front/packages/models/src/resources/server-info.ts +++ b/front/packages/models/src/resources/server-info.ts @@ -19,7 +19,8 @@ */ import { z } from "zod"; -import { baseAppUrl, imageFn } from ".."; +import { imageFn } from ".."; +import { Platform } from "react-native"; export const OidcInfoP = z.object({ /* @@ -32,30 +33,40 @@ export const OidcInfoP = z.object({ logoUrl: z.string().nullable(), }); -export const ServerInfoP = z.object({ - /* - * True if guest accounts are allowed on this instance. - */ - allowGuests: z.boolean(), - /* - * The list of permissions available for the guest account. - */ - guestPermissions: z.array(z.string()), - /* - * The list of oidc providers configured for this instance of kyoo. - */ - oidc: z.record(z.string(), OidcInfoP).transform((x) => - Object.fromEntries( - Object.entries(x).map(([provider, info]) => [ - provider, - { - ...info, - link: imageFn(`/auth/login/${provider}?redirectUrl=${baseAppUrl()}/login/callback`), - }, - ]), - ), - ), -}); +export const ServerInfoP = z + .object({ + /* + * True if guest accounts are allowed on this instance. + */ + allowGuests: z.boolean(), + /* + * The list of permissions available for the guest account. + */ + guestPermissions: z.array(z.string()), + /* + * The url to reach the homepage of kyoo (add /api for the api). + */ + publicUrl: z.string(), + /* + * The list of oidc providers configured for this instance of kyoo. + */ + oidc: z.record(z.string(), OidcInfoP), + }) + .transform((x) => { + const baseUrl = Platform.OS === "web" ? x.publicUrl : "kyoo://"; + return { + ...x, + oidc: Object.fromEntries( + Object.entries(x.oidc).map(([provider, info]) => [ + provider, + { + ...info, + link: imageFn(`/auth/login/${provider}?redirectUrl=${baseUrl}/login/callback`), + }, + ]), + ), + }; + }); /** * A season of a Show. diff --git a/front/packages/models/src/traits/images.ts b/front/packages/models/src/traits/images.ts index fc4db48d..9142e70d 100644 --- a/front/packages/models/src/traits/images.ts +++ b/front/packages/models/src/traits/images.ts @@ -25,8 +25,6 @@ import { lastUsedUrl } from ".."; export const imageFn = (url: string) => Platform.OS === "web" ? `/api${url}` : `${lastUsedUrl}${url}`; -export const baseAppUrl = () => (Platform.OS === "web" ? window.location.origin : "kyoo://"); - export const Img = z.object({ source: z.string(), blurhash: z.string(), diff --git a/front/packages/ui/src/settings/oidc.tsx b/front/packages/ui/src/settings/oidc.tsx index a40ea09a..49850068 100644 --- a/front/packages/ui/src/settings/oidc.tsx +++ b/front/packages/ui/src/settings/oidc.tsx @@ -19,7 +19,7 @@ */ import { QueryIdentifier, ServerInfo, ServerInfoP, useAccount, useFetch } from "@kyoo/models"; -import { A, Button, IconButton, Link, Skeleton, tooltip, ts } from "@kyoo/primitives"; +import { Button, IconButton, Link, Skeleton, tooltip, ts } from "@kyoo/primitives"; import { useTranslation } from "react-i18next"; import { ImageBackground } from "react-native"; import { rem, useYoshiki } from "yoshiki/native"; @@ -82,7 +82,9 @@ export const OidcSettings = () => { ) : (