Work on passing all env variables on server side.

This commit is contained in:
charlesgauthereau
2025-11-03 18:54:16 +01:00
parent 82559b49bd
commit bcbd6bbea1
9 changed files with 55 additions and 49 deletions
+1
View File
@@ -20,6 +20,7 @@ SMTP_FROM=
# Google
AUTH_GOOGLE_ID=
AUTH_GOOGLE_SECRET=
NEXT_PUBLIC_GOOGLE_AUTH=
# S3
S3_ENDPOINT=http://app.s3.portabase.io
-2
View File
@@ -1,7 +1,5 @@
"use client"
import React, {useEffect, useState} from "react";
import {LayoutAdmin} from "@/components/layout";
import Image from "next/image";
import {env} from "@/env.mjs";
import {useTheme} from "next-themes";
import {useSession} from "@/lib/auth/auth-client";
+8 -23
View File
@@ -1,32 +1,17 @@
"use client"
import {useEffect, useRef, useState} from "react";
import {useSearchParams} from "next/navigation";
import {notFound} from "next/navigation";
import {env} from "@/env.mjs";
import {LoginForm} from "@/components/wrappers/auth/login/login-form/login-form";
import {toast} from "sonner";
export default function SignInPage(props: {
searchParams: Promise<{ callbackUrl: string | undefined }>
}) {
export default async function SignInPage() {
const [urlParams, setUrlParams] = useState<URLSearchParams>();
useEffect(() => {
const urlParams = new URLSearchParams(window.location.search);
setUrlParams(urlParams);
const error = urlParams.get("error");
console.log(urlParams.get("redirect"));
if (error?.includes("pending")) {
toast.error("Your account is not active.");
urlParams.delete("error");
window.history.replaceState({}, document.title, window.location.pathname + "?" + urlParams.toString());
}
}, []);
const authGoogleEnabled = env.AUTH_GOOGLE_METHOD;
if (!authGoogleEnabled) {
notFound()
}
return (
<div className="mx-auto grid w-full gap-6">
<LoginForm/>
<LoginForm authGoogleEnabled={authGoogleEnabled}/>
</div>
)
}
+4 -4
View File
@@ -3,10 +3,10 @@ name: portabase-prod
services:
app:
# build:
# context: .
# dockerfile: docker/dockerfile/Dockerfile
# target: prod
# build:
# context: .
# dockerfile: docker/dockerfile/Dockerfile
# target: prod
image: solucetechnologies/portabase:1.1.3-rc.2
ports:
- '8887:80'
-3
View File
@@ -94,9 +94,6 @@ COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
COPY --chown=nextjs:nodejs src/db ./src/db
USER root
COPY ./docker/entrypoints/app-prod-entrypoint.sh /app/app-prod-entrypoint.sh
+1 -1
View File
@@ -1,6 +1,6 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
import "./.next/types/routes.d.ts";
import "./.next/dev/types/routes.d.ts";
// NOTE: This file should not be edited
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
@@ -1,10 +1,11 @@
"use client";
import { Button } from "@/components/ui/button";
import { signIn } from "@/lib/auth/auth-client";
import { JSX } from "react";
import {Button} from "@/components/ui/button";
import {signIn} from "@/lib/auth/auth-client";
import {JSX} from "react";
export type AuthButtonProps = {
providers: SocialProviderType[];
callBackURL?: string;
};
export type SocialProviderType = {
@@ -41,7 +42,7 @@ export const SocialAuthButton = (props: AuthButtonProps): JSX.Element => {
e.preventDefault();
void signIn.social({
provider: provider.id,
callbackURL: "/dashboard/profile",
callbackURL: props.callBackURL ?? "/dashboard/profile",
});
}}
>
@@ -15,10 +15,12 @@ import {SocialAuthButton, SocialProviderType} from "@/components/wrappers/auth/l
import {signIn} from "@/lib/auth/auth-client";
import {useRouter} from "next/navigation";
import {Icon} from "@iconify/react";
import {env} from "@/env.mjs";
import {useEffect, useState} from "react";
export type loginFormProps = {
defaultValues?: LoginType;
authGoogleEnabled: boolean;
};
export const LoginForm = (props: loginFormProps) => {
@@ -28,14 +30,35 @@ export const LoginForm = (props: loginFormProps) => {
schema: LoginSchema,
});
const [urlParams, setUrlParams] = useState<URLSearchParams>();
useEffect(() => {
const urlParams = new URLSearchParams(window.location.search);
console.log(urlParams);
setUrlParams(urlParams);
const error = urlParams.get("error");
console.log(urlParams.get("redirect"));
if (error?.includes("pending")) {
toast.error("Your account is not active.");
urlParams.delete("error");
window.history.replaceState({}, document.title, window.location.pathname + "?" + urlParams.toString());
}
}, []);
const mutation = useMutation({
mutationFn: async (values: LoginType) => {
const {error} = await signIn.email(values, {
onSuccess: () => {
toast.success("Login success");
router.push("/dashboard/profile");
},
});
const {error} = await signIn.email(
{
password: values.password,
email: values.email,
callbackURL: urlParams?.get("redirect") ?? "/dashboard/profile",
}, {
onSuccess: () => {
toast.success("Login success");
// router.push("/dashboard/profile");
},
});
if (error) {
toast.error(error.message);
}
@@ -44,7 +67,7 @@ export const LoginForm = (props: loginFormProps) => {
const availableProviders: SocialProviderType[] = [];
if (env.NEXT_PUBLIC_GOOGLE_AUTH) {
if (props.authGoogleEnabled) {
availableProviders.push(
{
id: "google",
@@ -115,7 +138,9 @@ export const LoginForm = (props: loginFormProps) => {
</Link>
</div>
</Form>
<SocialAuthButton providers={availableProviders}/>
<SocialAuthButton
callBackURL={urlParams?.get("redirect") ?? "/dashboard/profile"}
providers={availableProviders}/>
</CardContent>
</Card>
</TooltipProvider>
+2 -3
View File
@@ -22,7 +22,7 @@ export const env = createEnv({
AUTH_GOOGLE_ID: z.string().optional(),
AUTH_GOOGLE_SECRET: z.string().optional(),
NEXT_PUBLIC_GOOGLE_AUTH: z.boolean().default(false).optional(),
AUTH_GOOGLE_METHOD: z.boolean().default(false).optional(),
S3_ENDPOINT: z.string().optional(),
S3_ACCESS_KEY: z.string().optional(),
@@ -43,7 +43,6 @@ export const env = createEnv({
NEXT_PUBLIC_PROJECT_URL: z.string().optional(),
NEXT_PUBLIC_PROJECT_VERSION: z.string().optional(),
NEXT_PUBLIC_GOOGLE_AUTH: z.boolean().default(false).optional(),
},
runtimeEnv: {
NEXT_PUBLIC_PROJECT_NAME: process.env.NEXT_PUBLIC_PROJECT_NAME,
@@ -62,7 +61,7 @@ export const env = createEnv({
AUTH_GOOGLE_ID: process.env.AUTH_GOOGLE_ID,
AUTH_GOOGLE_SECRET: process.env.AUTH_GOOGLE_SECRET,
NEXT_PUBLIC_GOOGLE_AUTH: process.env.NEXT_PUBLIC_GOOGLE_AUTH === "true",
AUTH_GOOGLE_METHOD: process.env.AUTH_GOOGLE_METHOD === "true",
S3_ENDPOINT: process.env.S3_ENDPOINT,
S3_ACCESS_KEY: process.env.S3_ACCESS_KEY,