Next.js Discord

Discord Forum

issue accessing the dashboard's login page hosted on shared hosting service

Unanswered
Northeast Congo Lion posted this in #help-forum
Open in Discord
Northeast Congo LionOP
the websites domain is

https://www.rekangroup.com

the error i get on console is
GET https://rekangroup.com/dashboard/login?callbackUrl=%2Fdashboard 500 (Internal Server Error)
Navigated to https://rekangroup.com/dashboard/login?callbackUrl=%2Fdashboard

it works with no problem in locally but on the hosting service this is what i face im kinda hopless and need some help please.

11 Replies

Northeast Congo LionOP
this is the files i feel like might be connected

 server.js
/* eslint-disable @typescript-eslint/no-require-imports */
const next = require('next');
const express = require('express');

const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();

app.prepare().then(() => {
  const server = express();

  // Set NEXTAUTH_URL dynamically
  server.use((req, res, next) => {
    if (!process.env.NEXTAUTH_URL) {
      process.env.NEXTAUTH_URL = dev
        ? 'http://localhost:3000'
        : `https://${req.headers.host}`;
    }
    next();
  });

  server.all('*', (req, res) => {
    return handle(req, res);
  });

  const port = process.env.PORT || 3000;
  server.listen(port, (err) => {
    if (err) throw err;
    console.log(`> Ready on http://localhost:${port}`);
  });
}).catch((err) => {
  console.error('Error starting server:', err);
  process.exit(1);
});
.



 middleware.ts
//Src/middleware.ts
import { withAuth } from "next-auth/middleware";

export default withAuth({
  callbacks: {
    authorized: ({ token, req }) => {

      // Let login page be public
      if (req.nextUrl.pathname === "/dashboard/login") {
        return true;
      }
      // Otherwise require a valid session
      return !!token;
    },
  },
  pages: {
    signIn: "/dashboard/login",
  },
});

export const config = {
  matcher: [
    "/dashboard/:path*",
    "/api/admin/:path*",
  ],
};
check the server console
it will show you the errors
@Northeast Congo Lion
Northeast Congo LionOP
The error is the same as shown on the image and the provided error i gave on the posts description
Im not sure where to look for the error as to add debugs, but now i think about it it could be that the dashboard route is not recognised or misgonfigured from the middleware
@Diamond Master check the server console
Northeast Congo LionOP
^
Send screen
@Diamond Master Send screen
Northeast Congo LionOP
it was middleware issue, after removing it the dashboard rendered and now i have to fix it