The Vercel public domain is not functioning as expected

After successfully developing a next.js application with user auth using NextAuth and deploying it to Vercel, I encountered an issue related to the notifications page functionality. The problem arises when the app checks for an active session; if none is found, it automatically redirects users from the /notifications route back to the index page to ensure that only authenticated users can access the notifications section.

Included below is a screenshot displaying the three different domains available on my Vercel deployment. As a newcomer to Vercel, I am uncertain about the specific purposes of each link. However, I've noticed that I'm unable to share the third link, leading me to believe that the first link is meant for public access, such as sharing the app with friends.

During development on localhost and within the third domain on Vercel, the feature functioned flawlessly. However, upon deployment to the first domain accessible to the general public, the /notifications route consistently redirected me to the index page regardless of my authentication status. This malfunction in the public domain raised concerns over the usability of the app.

Upon investigating this issue further, I came across an error in the Vercel logs:

[next-auth][error][CLIENT_FETCH_ERROR] 
https://next-auth.js.org/errors#client_fetch_error Unexpected token < in JSON at position 0 {
  error: {
    message: 'Unexpected token < in JSON at position 0',
    stack: 'SyntaxError: Unexpected token < in JSON at position 0\n' +
      '    at JSON.parse (<anonymous>)\n' +
      '    at parseJSONFromBytes (node:internal/deps/undici/undici:6662:19)\n' +
      '    at successSteps (node:internal/deps/undici/undici:6636:27)\n' +
      '    at node:internal/deps/undici/undici:1236:60\n' +
      '    at node:internal/process/task_queues:140:7\n' +
      '    at AsyncResource.runInAsyncScope (node:async_hooks:203:9)\n' +
      '    at AsyncResource.runMicrotask (node:internal/process/task_queues:137:8)\n' +
      '    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)',
    name: 'SyntaxError'
  },
  url: 'https://switter-deploy-xxxxxxxxx-xxxxxxxxxx-projects.vercel.app/api/auth/session',
  message: 'Unexpected token < in JSON at position 0'
}

This error appears after attempting to view notifications while logged in, resulting in a redirection to the index page. Despite encountering this error and landing on the index page instead of the notifications page, the network tab displays a status of 200 (OK).

In summary, I am puzzled by the discrepancy in functionality between the notification route on localhost, the third domain, and the first domain — which is intended for public access. I seek clarity on why the notifications work smoothly in some instances but fail in others.

deployment domains

import Header from "@/components/Header"
import NotificationsFeed from "@/components/NotificationsFeed"
import useCurrentUser from "@/hooks/useCurrentUser"
import { NextPageContext } from "next"
import { getSession } from "next-auth/react"

export async function getServerSideProps(context: NextPageContext) {
  const session = await getSession(context)
  console.log("Session:", session)

  if (!session) {
    return {
      redirect: {
        destination: "/",
        permanent: false,
      },
    }
  }
  return {
    props: {
      session,
    },
  }
}

const Notifications = () => {
  return (
    <>
      <Header showBackArrow label="Notifications" />
      <NotificationsFeed />
    </>
  )
}

export default Notifications

Answer №1

The issue arises from the lack of JSON response from the URL. It is difficult to confirm without visibility into the actual URLs, but typically one would need to specify a NEXT_AUTH_URL or equivalent to guide NextAuth in locating the API calls. My suspicion is that the obscured portion of the URL does not align, as certain URLs generated by Vercel may include a hash that varies upon redeployment.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Implementing inline styles in the HEAD section of a Next.js website

I currently have a blog hosted on Jekyll at , and I'm looking to migrate it to Next.js. My unique approach involves embedding all the styles directly into the HEAD element of each HTML page, without utilizing any external stylesheet files. However, wh ...

Retrieve contextual information within standard providers

I'm currently using nestjs to create a straightforward HTTP rest API, utilizing typeorm. I have set up 2 Postgres databases and would like the ability to access both, although not necessarily simultaneously. Essentially, I am looking to designate whi ...

The 'posts' binding element is assumed to have a type of 'any' by default

Currently, I'm working on a code project that involves graphql, react, and typescript. In the middle of the process, I encountered an error message stating "Binding element 'posts' implicitly has an 'any' type." I am unsure about w ...

Can HTML variables be accessed in lines of code before they are declared in HTML?

In line 1 of my code, I am trying to access the rowData variable which is declared in the second HTML line. However, I keep getting the error message "Property 'rowData' does not exist on type 'AppComponent'" for that line. Strangely, t ...

Position components in Angular 2 based on an array's values

Hello all, I am a beginner in terms of Angular 2 and currently facing some obstacles. My goal is to create a board for a board game called Reversi, which has a similar layout to chess but with mono-color pieces. In order to store the necessary information, ...

Building a table with Next.js

I need assistance in displaying users and their metadata in a table on my website. Here is the code snippet I have: const apiKey = process.env.CLERK_SECRET_KEY; if (!apiKey) { console.error('API_KEY not found in environment variables'); proc ...

Can a page name and folder name containing dynamic pages be identical?

insert image overview here In the image above, I have a section called "Movies" along with a directory named movies I am trying to navigate so that if the URL in the address bar is '/movies', it directs me to the "movies.js" page. Only when the ...

Transition from using ReactDOM.render in favor of asynchronous callback to utilize createRoot()

Is there a React 18 equivalent of this code available? How does it handle the asynchronous part? ReactDOM.render(chart, container, async () => { //code that styles some chart cells and adds cells to a worksheet via exceljs }) ...

Results don't align with search parameters

const searchClientes = (event) => { if (event.target.value === '') { getClientes(); return; } else { const searchTerm = event.target.value; const filteredClients = clientes.filter(cliente => { return cliente.nome ...

Error: Unable to execute function on blog mapping

I am facing an issue with my app where it fails to detect objects. Every time the component in my app calls ".map", I encounter an error message. I have double-checked that index.js is passing props correctly. Can anyone explain why this problem is occurri ...

NextJS Typescript Layout is throwing errors due to the absence of required props

After following the instructions on https://nextjs.org/docs/basic-features/layouts#with-typescript and making changes to my Home page as well as _app.tsx, I encountered an issue with the layout file Layout.tsx. The provided guide did not include an exampl ...

What is the method for inserting a specific index into an interface array in TypeScript?

In my angular(typescript) application, I have an interface defined as follows: export interface PartnerCnic{ id: string; shipperRegCnicFront: File; shipperRegCnicBack: File; } Within my component, I have initialized an empty array for this interface li ...

The TypeScript error is causing issues in the Express router file

Here is the structure of my module: import * as express from 'express'; let router = express.Router(); router.post('/foo', function(req,res,next){ // ... }); export = router; However, I'm encountering the following error: ...

Can you explain the distinction between nextjs and nuxtjs?

Greetings! As I delve into a new project, I stumbled upon next and nuxtjs. I am curious about the advantages of incorporating either of them into my project. Can you shed some light on this? ...

Preloading Images in Next.js: How to Load Images on Website Launch Before Reaching the Displayed Page

I am currently working on a website with a gallery using nextjs. I am trying to preload all the assets from the gallery as soon as the page loads, but I can't seem to figure out how to do it. I've attempted hiding a link to the gallery in various ...

Angular Authentication Functionality

I need to create a loggedIn method in the AuthService. This method should return a boolean indicating the user's status. It will be used for the CanActivate method. Here is a snippet of code from the AuthService: login(email: string, password: string) ...

The use of 'import ... =' is restricted to TypeScript files

Error: Oops! Looks like there's a hiccup in the code... 'import ... =' is exclusive to TypeScript files. Expecting '=' here. Don't forget the ';'. Unexpected keyword or identifier popping up! package.json ...

Issue with InversifyJS @multiInject: receiving an error stating "ServiceIdentifier has an ambiguous match"

Having an issue with inversifyJs while trying to implement dependency injection in my TypeScript project. Specifically, when using the @multiInject decorator, I keep receiving the error "Ambiguous match found for serviceIdentifier". I've been referenc ...

Resolving the "Abstract type N must be an Object type at runtime" error in GraphQL Server Union Types

Given a unique GraphQL union return type: union GetUserProfileOrDatabaseInfo = UserProfile | DatabaseInfo meant to be returned by a specific resolver: type Query { getUserData: GetUserProfileOrDatabaseInfo! } I am encountering warnings and errors rel ...

When simulating a React component, it is essential to note that the property 'default' must

Upon embarking on a new React/Next.js project, I encountered an issue with mocking memoized React components that I had not experienced in previous projects. Despite my efforts, I could not figure out the root cause of this discrepancy. Allow me to provide ...