Back

Dockerized Next.js 14 app gives error during registration/login

  • 0
  • Self Hosted
  • Auth
  • Web
Heisenberg
25 Mar, 2024, 22:41

Hi, I'm running a self hosted instance of Appwrite. I have a Next.js app router app where I've implemented registration by following the guide at: https://appwrite.io/docs/tutorials/nextjs-ssr-auth/step-5

I'm running the Next.js app using Docker, and when I try to register I get this error

TL;DR
Developers are facing an error with their Dockerized Next.js 14 app during registration/login. The issue seems to be related to the environment variables setup and the deployment of the Docker app. The error logs suggest a fetch failure and a specific location within the code where the error occurs. They are also running a self-hosted instance of Appwrite.
Heisenberg
25 Mar, 2024, 22:42

I investigated the build as well as the docker logs

Heisenberg
25 Mar, 2024, 22:43

Docker error logs:

TypeScript
 e [Error]: fetch failed
rapidproductshoots-1  |     at g.call (/app/.next/server/chunks/913.js:1:2552)
rapidproductshoots-1  |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
rapidproductshoots-1  |     at async n.create (/app/.next/server/chunks/913.js:1:13522)
rapidproductshoots-1  |     at async x (/app/.next/server/app/register/page.js:1:10131)
rapidproductshoots-1  |     at async /app/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:16:406
rapidproductshoots-1  |     at async rm (/app/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:15:6342)
rapidproductshoots-1  |     at async rq (/app/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:18:1249)
rapidproductshoots-1  |     at async doRender (/app/node_modules/next/dist/server/base-server.js:1378:30)
rapidproductshoots-1  |     at async cacheEntry.responseCache.get.routeKind (/app/node_modules/next/dist/server/base-server.js:1539:28)
rapidproductshoots-1  |     at async NextNodeServer.renderToResponseWithComponentsImpl (/app/node_modules/next/dist/server/base-server.js:1447:28) {
rapidproductshoots-1  |   code: undefined,
rapidproductshoots-1  |   type: undefined,
rapidproductshoots-1  |   response: undefined
rapidproductshoots-1  | }
Heisenberg
25 Mar, 2024, 22:43

rapidproductshoots-1 | at async x (/app/.next/server/app/register/page.js:1:10131)

That location contains these lines: ,{account:a}=await (0,l.createAdminClient)();await a.create(c.ID.unique(),t,s,r);let i=await a.createEmailPasswordSession(t,s);

Heisenberg
25 Mar, 2024, 22:44

I've also added the hostname correctly to my appwrite project platform

Heisenberg
25 Mar, 2024, 22:47

The code itself:

TypeScript
import { getLoggedInUser } from "@/lib/appwrite";
import { redirect } from "next/navigation";
import { ID } from "node-appwrite";
import { createAdminClient } from "@/lib/appwrite";
import { cookies } from "next/headers";

async function signUpWithEmail(formData: any) {
    "use server";

    const email = formData.get("email");
    const password = formData.get("password");
    const name = email.split("@")[0];
    const { account } = await createAdminClient();
    await account.create(ID.unique(), email, password, name);
    const session = await account.createEmailPasswordSession(email, password);

    cookies().set("my-custom-session", session.secret, {
        path: "/",
        httpOnly: true,
        sameSite: "strict",
        secure: true,
    });

    redirect("/create");
}

export default async function Register() {
    const user = await getLoggedInUser();
    if (user) redirect("/create");

    return (
                    <form
                        action={signUpWithEmail}
                        className=""
                    >
                        <input
                            id="email"
                            name="email"
                            placeholder="Email"
                            type="email"
                            className=""
                        />
                        <input
                            id="password"
                            name="password"
                            placeholder="Password"
                            minLength={8}
                            type="password"
                            className=""
                        />
                        <button
                            className=""
                            type="submit"
                        >
                            Get Started
                        </button>

                    </form>
    );
}
Heisenberg
25 Mar, 2024, 22:48

The same error occurs while trying to login as well

Heisenberg
25 Mar, 2024, 22:48

The code works fine locally, the issue is for the deployed docker app

Heisenberg
25 Mar, 2024, 22:56

Would appreciate any support on this, been stuck for a while 😅

Kenny
25 Mar, 2024, 22:57

You’ve just posted this 15 minutes ago

Heisenberg
25 Mar, 2024, 23:03

Sorry didn't mean to nag, just wanted to add I'd appreciate support. I understand all support is community driven and it may take time for someone to get around to help, or no one might at all. Sorry for the bad phrasing

Kenny
25 Mar, 2024, 23:05

Just verifying are all your environment variable setup correctly?

Heisenberg
25 Mar, 2024, 23:08

Yes, I verified in the build

Heisenberg
25 Mar, 2024, 23:08

The NEXTPUBLIC_* API Keys are replaced by the raw strings in the build

Heisenberg
25 Mar, 2024, 23:09

and docker exec container env prints out the NEXT_APPWRITE_KEY aswell

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more