Encountering a "No session persistence storage option available" error while working on a Next.js 12 + Supabase project

I'm currently working on a project that involves Supabase and Next.js version 12.3.4. I managed to set up Google sign-in following the steps outlined in this helpful tutorial: Supabase Login with Google. However, every time I run the project, Terminal keeps warning me:

No storage option exists to persist the session, which may result in unexpected behavior when using auth.
        If you want to set persistSession to true, please provide a storage option or you may set persistSession to false to disable this warning.
    

Here is the snippet of code used for signing in:

import supabaseClient from "./supabaseClient";

    export default async function signInWithGoogle() {
        const { data, error } = await supabaseClient.auth.signInWithOAuth({
            provider: 'google',
            options: {
                redirectTo: 'http://localhost:3000/account'
            }
        })
    }
    

In response to another similar issue posted on Reddit here, one suggestion was to follow this tutorial. I attempted this since my project also includes a pages directory. However, the tutorial's instructions refer to an src/App.jsx file with an App function whereas my setup uses a pages/_app.js file with "export default class MyApp extends App". Following the recommended code in _app.js led to an error message saying

Error: Invalid hook call. Hooks can only be called inside of the body of a function component.

This is a portion of my _app.js file:

import App from 'next/app'
    import Head from 'next/head'
    import React from 'react'
    import { Analytics } from '@vercel/analytics/react';
    import font from "/components/styles.css";
    
    export default class MyApp extends App {
        static async getInitialProps({ Component, ctx }) {
            let pageProps = {}
    
            if (Component.getInitialProps) {
                pageProps = await Component.getInitialProps(ctx)
            }
    
            return { pageProps }
        }
    
        render() {
            const { Component, pageProps } = this.props
    
            return (
                <>
                    <Head>
                        <title>words</title>
                    
                    </Head>
                    <Component {...pageProps} />
                    <Analytics />
                </>
            )
        }
    }
    

Can anyone help me resolve the storage error? I am fairly new to all these technologies so any assistance would be greatly appreciated. Thank you!

Answer №1

I encountered a similar problem while working with supabase in my node environment. Hopefully this solution will help resolve your issue as well.

const supabase = createClient(supabaseUrl, supabaseKey, {
  auth: { persistSession: false },
});

Answer №2

Integrating Redux with Supabase for state management can be done seamlessly by utilizing redux-persist along with redux-persist/lib/storage as the storage method. This simple adjustment will resolve any warning messages.

import storage from 'redux-persist/lib/storage';
const supabase = createClient( supabaseUrl, supabaseKey, {auth: {storage: storage}}); 

Answer №3

In my situation, I encountered an issue with my superbase createClient being in a separate file and imported on the client side. Surprisingly, this caused the code to also run on the server during SSR.

To resolve this issue, I simply removed the extra file and placed the createClient call inside an empty useEffect hook. This simple adjustment solved the problem.

For example:

const [supabase, setSupabase] = useState(null)

  useEffect(() => {
    setSupabase(createClient(config.SUPABASE_URL, config.SUPABASE_KEY));
  }, []);

I hope this explanation is helpful!

Answer №4

I appreciate the responses from both of you. While my solution may not fully align with the original question's parameters, I found success by upgrading the project to Nextjs 13. This upgrade made another aspect of the project much more manageable. Post-upgrade, I followed a tutorial to set up Supabase: and made changes to the signInWithGoogle function as demonstrated below:

import { createClientComponentClient } from "@supabase/auth-helpers-nextjs"

export default async function signInWithGoogle() {
    const supabase = createClientComponentClient()
    const { data, error } = await supabase.auth.signInWithOAuth({
        provider: 'google',
        options: {
            redirectTo: 'http://localhost:3000/auth/callback'
        }
    })
}

After upgrading the project, the errors ceased.

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

Ways to manage multiple requests simultaneously on my API

I am encountering an issue with my API endpoint that manages available rooms in a hotel. Whenever a customer sends a POST/GET request to the API, it searches for an available room and assigns the room number to them. Here is the code snippet: const db = aw ...

Exploring Next.js: Leveraging GraphQL and a Headless CMS (graphCMS) for Client-Side Data Retrieval

I've run into an issue while trying to fetch data in a client-side component using the Next.js app directory, and I could really use some help resolving it. My requirement involves fetching data with graphql from graphCMS within a client-side compone ...

An unexpected error occurred during runtime: Failed request with status code 500 in NextJS

I've been following a tutorial on cloning Amazon and despite having the same code as in the video, I keep encountering an error. I generated new keys for Firebase and Stripe, and even adjusted the Shipping Rates in Stripe. The error message can be see ...

Guide on setting up and customizing run.json within the latest JetBrains Fleet for Next.js

I've been attempting to set up input/output for the latest IDE from JetBrains, Fleet. However, I've hit a roadblock and can't seem to figure it out on my own. That's why I'm turning to the Stack Overflow community for help - how do ...

Signing out with Next-Auth redirects to the local host address 127.0.0.1

When attempting to sign out of my logged in session using the next-auth signOut function in Next.js, I am being redirected to 127.0.0.1 and getting an error saying "127.0.0.1 refused to connect". I'm not sure why this is happening as it should be redi ...

When a user clicks on a child element of an anchor tag, the function will

Is it possible to return a specific function when a user clicks on a child of an anchor element? <a href="/product/product-id"> I am a product <div> Add to favorites </div> </a> const handleClick = (event) =>{ ...

The argument of type 'NextRouter' cannot be assigned to the parameter of type 'Props' in this scenario

In my component, I am initializing a Formik form by calling a function and passing the next/router object. This is how it looks: export default function Reset() { const router = useRouter(); const formik = useFormik(RecoverForm(router)); return ( ...

What potential drawbacks could I encounter if I decide to convert all files in a Next.js project from .js to .jsx?

Our administration panel is built with Vite + React, while our landing pages utilize Qwik + Vite. Both projects are using the .jsx file extension instead of TypeScript. It's worth noting that Next.js defaults to using .js for its files. We're ...

utilizing a dynamic value within CSS modules for class naming

Struggling to incorporate a variable into a CSS module class name in Next.js. Finding it challenging to determine the correct syntax. The variable is fetched from the API: const type = red Here's how I'm attempting to achieve it: <div clas ...

What kind of output should a Server Side Component generate?

Recently, I decided to incorporate the NextPage type from Next.js into my component writing routine after hearing it's a beneficial practice. However, I discovered that it only functions properly with client-side components. When attempting to utilize ...

An issue occurred during the hydration process, causing the entire root to switch to client rendering since the error occurred outside of a Suspense boundary

I've started seeing some errors and warnings: Error: An error occurred while hydrating. Since it happened outside of a Suspense boundary, the entire root will switch to client rendering. Error: Hydration failed due to initial UI not matching what was ...

Next.js: Dealing with special characters in YouTube video API snippet titles

Trying to find the perfect video snippet title without any special characters. Accessing the API: https://www.googleapis.com/youtube/v3/search, along with specifying snippet. The current output for snippet.title is as follows: I&#39;M GONNA CARRY ...

Having trouble displaying the correct data for the Title in NextJs Head? Any solutions available?

Hi there, I am currently utilizing the <Head/> Tag from an API in my NextJs project. All meta tags are functioning properly except for the title meta tag, which seems to be displaying the first H1 on the page instead. Here is the code snippet: ...

Get image data from Next.JS API and show it in the web browser

I am looking to utilize my own next.js endpoints to request an image that I can then embed into my website. Currently, the issue I am facing is that the image seems to be immediately downloaded and does not display in the browser window. import type { Next ...

Error encountered: The function store.getState is not defined in the Next.js application

I encountered an issue while creating a redux store in my Next.js and React.js app. The error message "Uncaught TypeError: store.getState is not a function" appears when I try to access the store without using a provider. Can someone assist me with resolvi ...

The navigation between pages is determined by the route taken (Utilizing Next.js 14 and Framer Motion)

In the app I'm developing, I have integrated a tab-style navigation bar to enable smooth movement between various categories of places, each with its unique route. The transitions between these routes are achieved by utilizing the following code snipp ...

Prisma and Next.js: Changes to content require re-deployment for updates to take effect

Just recently, I launched a new website on Vercel. My web application is being built with Prisma and Next.js. However, I'm currently facing an issue where the content doesn't update in real-time unless I manually re-deploy the application. Here&a ...

The data structure '{ recipe: null; }' cannot be matched with type 'IntrinsicAttributes & Recipe'

Currently, I am working on an app that integrates ChatGPT to fetch recipes based on user-input ingredients. After receiving the JSON response from CGPT, I aim to display a Recipe "Card" component. However, I encounter an error titled above when attempting ...

Learn how to display a loading state only when the data has not been received yet in a server-side rendered Next.js application

In my project, I have implemented multiple instances of the getServerSideProps function. When a user clicks on a page in the header, data needs to be fetched before the page can be displayed. To notify users of a loading state, I initially tried using the ...

Exploring Next.js 13: Enhancing Security with HTTP Cookie Authentication

I'm currently working on a web app using Next.js version 13.4.7. I am setting up authentication with JWT tokens from the backend (Laravel) and attempting to store them in http-only cookies. Within a file named cookie.ts, which contains helper functio ...