mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
Work on passing all env variables on server side.
This commit is contained in:
@@ -20,6 +20,7 @@ SMTP_FROM=
|
|||||||
# Google
|
# Google
|
||||||
AUTH_GOOGLE_ID=
|
AUTH_GOOGLE_ID=
|
||||||
AUTH_GOOGLE_SECRET=
|
AUTH_GOOGLE_SECRET=
|
||||||
|
NEXT_PUBLIC_GOOGLE_AUTH=
|
||||||
|
|
||||||
# S3
|
# S3
|
||||||
S3_ENDPOINT=http://app.s3.portabase.io
|
S3_ENDPOINT=http://app.s3.portabase.io
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
"use client"
|
"use client"
|
||||||
import React, {useEffect, useState} from "react";
|
import React, {useEffect, useState} from "react";
|
||||||
import {LayoutAdmin} from "@/components/layout";
|
|
||||||
import Image from "next/image";
|
|
||||||
import {env} from "@/env.mjs";
|
import {env} from "@/env.mjs";
|
||||||
import {useTheme} from "next-themes";
|
import {useTheme} from "next-themes";
|
||||||
import {useSession} from "@/lib/auth/auth-client";
|
import {useSession} from "@/lib/auth/auth-client";
|
||||||
|
|||||||
@@ -1,32 +1,17 @@
|
|||||||
"use client"
|
import {notFound} from "next/navigation";
|
||||||
|
import {env} from "@/env.mjs";
|
||||||
import {useEffect, useRef, useState} from "react";
|
|
||||||
import {useSearchParams} from "next/navigation";
|
|
||||||
|
|
||||||
import {LoginForm} from "@/components/wrappers/auth/login/login-form/login-form";
|
import {LoginForm} from "@/components/wrappers/auth/login/login-form/login-form";
|
||||||
import {toast} from "sonner";
|
|
||||||
|
|
||||||
export default function SignInPage(props: {
|
export default async function SignInPage() {
|
||||||
searchParams: Promise<{ callbackUrl: string | undefined }>
|
|
||||||
}) {
|
|
||||||
|
|
||||||
const [urlParams, setUrlParams] = useState<URLSearchParams>();
|
const authGoogleEnabled = env.AUTH_GOOGLE_METHOD;
|
||||||
|
if (!authGoogleEnabled) {
|
||||||
useEffect(() => {
|
notFound()
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mx-auto grid w-full gap-6">
|
<div className="mx-auto grid w-full gap-6">
|
||||||
<LoginForm/>
|
<LoginForm authGoogleEnabled={authGoogleEnabled}/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -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 --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||||
COPY --chown=nextjs:nodejs src/db ./src/db
|
COPY --chown=nextjs:nodejs src/db ./src/db
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
USER root
|
USER root
|
||||||
|
|
||||||
COPY ./docker/entrypoints/app-prod-entrypoint.sh /app/app-prod-entrypoint.sh
|
COPY ./docker/entrypoints/app-prod-entrypoint.sh /app/app-prod-entrypoint.sh
|
||||||
|
|||||||
Vendored
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
/// <reference types="next" />
|
/// <reference types="next" />
|
||||||
/// <reference types="next/image-types/global" />
|
/// <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
|
// NOTE: This file should not be edited
|
||||||
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
|
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { JSX } from "react";
|
|||||||
|
|
||||||
export type AuthButtonProps = {
|
export type AuthButtonProps = {
|
||||||
providers: SocialProviderType[];
|
providers: SocialProviderType[];
|
||||||
|
callBackURL?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type SocialProviderType = {
|
export type SocialProviderType = {
|
||||||
@@ -41,7 +42,7 @@ export const SocialAuthButton = (props: AuthButtonProps): JSX.Element => {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
void signIn.social({
|
void signIn.social({
|
||||||
provider: provider.id,
|
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 {signIn} from "@/lib/auth/auth-client";
|
||||||
import {useRouter} from "next/navigation";
|
import {useRouter} from "next/navigation";
|
||||||
import {Icon} from "@iconify/react";
|
import {Icon} from "@iconify/react";
|
||||||
import {env} from "@/env.mjs";
|
import {useEffect, useState} from "react";
|
||||||
|
|
||||||
export type loginFormProps = {
|
export type loginFormProps = {
|
||||||
defaultValues?: LoginType;
|
defaultValues?: LoginType;
|
||||||
|
authGoogleEnabled: boolean;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const LoginForm = (props: loginFormProps) => {
|
export const LoginForm = (props: loginFormProps) => {
|
||||||
@@ -28,12 +30,33 @@ export const LoginForm = (props: loginFormProps) => {
|
|||||||
schema: LoginSchema,
|
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({
|
const mutation = useMutation({
|
||||||
mutationFn: async (values: LoginType) => {
|
mutationFn: async (values: LoginType) => {
|
||||||
const {error} = await signIn.email(values, {
|
const {error} = await signIn.email(
|
||||||
|
{
|
||||||
|
password: values.password,
|
||||||
|
email: values.email,
|
||||||
|
callbackURL: urlParams?.get("redirect") ?? "/dashboard/profile",
|
||||||
|
}, {
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
toast.success("Login success");
|
toast.success("Login success");
|
||||||
router.push("/dashboard/profile");
|
// router.push("/dashboard/profile");
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (error) {
|
if (error) {
|
||||||
@@ -44,7 +67,7 @@ export const LoginForm = (props: loginFormProps) => {
|
|||||||
|
|
||||||
const availableProviders: SocialProviderType[] = [];
|
const availableProviders: SocialProviderType[] = [];
|
||||||
|
|
||||||
if (env.NEXT_PUBLIC_GOOGLE_AUTH) {
|
if (props.authGoogleEnabled) {
|
||||||
availableProviders.push(
|
availableProviders.push(
|
||||||
{
|
{
|
||||||
id: "google",
|
id: "google",
|
||||||
@@ -115,7 +138,9 @@ export const LoginForm = (props: loginFormProps) => {
|
|||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
</Form>
|
</Form>
|
||||||
<SocialAuthButton providers={availableProviders}/>
|
<SocialAuthButton
|
||||||
|
callBackURL={urlParams?.get("redirect") ?? "/dashboard/profile"}
|
||||||
|
providers={availableProviders}/>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</TooltipProvider>
|
</TooltipProvider>
|
||||||
|
|||||||
+2
-3
@@ -22,7 +22,7 @@ export const env = createEnv({
|
|||||||
|
|
||||||
AUTH_GOOGLE_ID: z.string().optional(),
|
AUTH_GOOGLE_ID: z.string().optional(),
|
||||||
AUTH_GOOGLE_SECRET: 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_ENDPOINT: z.string().optional(),
|
||||||
S3_ACCESS_KEY: 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_URL: z.string().optional(),
|
||||||
NEXT_PUBLIC_PROJECT_VERSION: z.string().optional(),
|
NEXT_PUBLIC_PROJECT_VERSION: z.string().optional(),
|
||||||
|
|
||||||
NEXT_PUBLIC_GOOGLE_AUTH: z.boolean().default(false).optional(),
|
|
||||||
},
|
},
|
||||||
runtimeEnv: {
|
runtimeEnv: {
|
||||||
NEXT_PUBLIC_PROJECT_NAME: process.env.NEXT_PUBLIC_PROJECT_NAME,
|
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_ID: process.env.AUTH_GOOGLE_ID,
|
||||||
AUTH_GOOGLE_SECRET: process.env.AUTH_GOOGLE_SECRET,
|
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_ENDPOINT: process.env.S3_ENDPOINT,
|
||||||
S3_ACCESS_KEY: process.env.S3_ACCESS_KEY,
|
S3_ACCESS_KEY: process.env.S3_ACCESS_KEY,
|
||||||
|
|||||||
Reference in New Issue
Block a user