"Supabase's getUserByCookie function is malfunctioning when accessed on a mobile

Having trouble testing my app on a mobile device because it is not receiving cookies from server-side requests. (works fine in Chrome) In the Next.js getServerSideProps function, I have the following code:

export async function getServerSideProps({ req }) {
  const { user } = await supabase.auth.api.getUserByCookie(req)

  console.log('user from cookie', user)

  if (!user) {
    return { props: {}, redirect: { destination: '/sign-in' } }
  }
  const { data: teams } = await supabase
    .from('teams')
    .select('*')
    .eq('user_id', user.id)

  // handle user data...
  return {
    props: {
      teams,
    },
  }
}

This code returns a user object when tested on Chrome or any other web browser, but fails to do so on mobile devices where it returns user = null.

I suspect the issue lies with the cookie session handling. Any advice on how to resolve this would be greatly appreciated.

Answer №1

When facing an issue with cookies and Supabase, I managed to resolve it by utilizing my service key for the server-side code.

To address this, you can create a new client in your Supabase client file and export it as follows:

   export const getServiceSupabase = () =>
  createClient(
    process.env.NEXT_PUBLIC_SUPABASE_URL,
    process.env.SUPABASE_SERVICE_KEY
  );

Subsequently, integrate this client into your getServerSideProps() function.

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

Why is TypeScript unable to recognize package exports? (using CommonJS as the module system and Node as the module resolution)

I have an NPM package that is built for ESM and CJS formats. The package has a dist folder in the root directory, which contains: dist/esm - modules with ESM dist/cjs - modules with CJS dist/types - typings for all modules In the package.json file, there ...

Enabling authentication for MongoDB on Ubuntu Desktop ensures a secure way to access your

Currently using Ubuntu 16.04 and attempting to enable authentication in mongodb I have created a new User with the following code: db.createUser({ user:"Sun", pwd:"Sun", roles:[{role:"userAdmin",db:"pet"}] }) I have verified the user with: db.getUsers( ...

What makes React Router distinct as a React component?

What is the reasoning behind react-router being a React Component that utilizes React internally? As routing issues were already addressed before the introduction of React Components? In the case where the path property does not align with the URL path, w ...

Enhance the Material UI StepIcon by embedding real icons within the background circle

I have scoured through stack overflow but haven't come across a specific question addressing my issue. I am working on styling a Material UI Stepper component in a unique way. Most examples I've found use withStyles or makeStyles for color custom ...

Switching between numerical and alphabetical input using JQuery

How can I switch between allowing character and numeric input in a textbox? I currently have a JQuery function that restricts input to numbers only $('.numeric').on('input', function (event) { this.value = this.value.replace(/[^0 ...

Error encountered: "Unable to process Three.js FontLoader due to SyntaxError

I attempted to generate 3D text with FontLoader in Three.js, but encountered an error. My Three.js version is r99. const loader = new THREE.FontLoader(); //https://github.com/mrdoob/three.js/tree/dev/examples/fonts loader.load("./fonts/helvetiker_ ...

Is it possible to run a local file on a localhost server in Sublime Text 3 with the help of the SideBar

I am attempting to host my index.html file on a localhost server in order to utilize an angular routing directive. Despite following the steps, I am encountering issues. //sidebarenchancements.json { "file:///C:/Users/Jdog/Desktop/projects/Calibre/soci ...

The light/dark mode toggle is a one-time use feature

I've been experimenting with creating a button to toggle between light and dark modes on my website. Initially, it's set to light mode, but when I try switching to dark mode, it works fine. However, the issue arises when attempting to switch back ...

Exploring the capabilities of Firebase functions within a Vue.js environment

I've been working on unit testing my Vue components, but it's posing challenges due to the integration with Firebase. To address this issue, I decided to set up a dedicated folder named __mocks__ for storing all my mocked functions. Within this f ...

Error: Trying to access 'whenReady' property of undefined variable is not allowed

As a beginner in electron app development, I am facing an issue when running npm start from the terminal. The error message I receive is: TypeError: Cannot read properties of undefined (reading 'whenReady')... This specific problem seems to be ...

Tips for invoking both a typescript arrow function and a regular javascript function within one event

Is it possible to call both a JavaScript function and a TypeScript function from the same onClick event in a chart? I am new to TypeScript and Angular, so I'm not sure if this is achievable. The issue at hand is that I need to invoke a JavaScript fun ...

Transferring an array from PHP to JavaScript within a function

Having trouble accessing the array returned by a PHP function in JavaScript. Instead of seeing the actual array, I get the message: function Array() { [native code] } How can I retrieve and work with the items in the array? When I try using alert(pad ...

I am looking to initiate the animation by triggering the keyframe upon clicking a button

Is there a way to create an animation triggered by a button click instead of loading the page? Each table data cell has its own class with a unique keyframe defining the style changes over time. @-webkit-keyframes fadeIn { from { opacity:0; ...

Unusual behavior observed when altering properties of checkboxes

Here is the code snippet in question: <table border="1" style="margin:0 auto;"> <tr> <td class="pointer" style="padding: 2px;"><input style="margin-left: 2px;" type="checkbox" name="nuovoCheck" id="newCheckId" value="N" /& ...

Using jQuery to populate a select box with values from an XML file

I've come across various examples demonstrating how to achieve this task and have successfully applied others that utilize attributes. However, in the current scenario, I am working with XML data that does not contain attributes. My goal is to populat ...

Implementing a click event for multiple controls by utilizing class names in Angular

I have been able to successfully attach a click event in Angular using the following method: <span (click)="showInfo()" class="info-span"></span> However, I have 20 spans with similar attributes. Is there a more centralized ...

The function "getElementsByClassName" in Javascript is malfunctioning

I have redesigned my website by implementing an interactive feature where users can click on a tree image to remove it and replace it with a number using JavaScript. Initially, I targeted the specific tree with the following code: document.getElementById( ...

Can you please provide instructions on how to expand the view in the title bar for a JavaScript/CSS/HTML UPW project?

Struggling to integrate the title bar in a UWP project using JavaScript/CSS/HTML and having trouble accessing the necessary APIs. Came across a custom helper class written in c++ in UWP samples on Github, but unable to reference it in my javascript code. H ...

Loading a project statically without relying on webpack or content delivery networks

How can I serve a project statically, which utilizes webcomponents (using lit-html), without using any packaging tools like webpack? The project structure includes: index.html app.js package.json package.json: { "name": "lit", "version": "1.0.0", ...

Exposing a Hidden Division with a Link via jQuery

I currently have a jQuery Panel set up to open when clicking a button. Now, I am looking to add a second link at the bottom of the page that will also open the same panel. Can anyone provide guidance on how to accomplish this? You can view my JSFiddle a ...