Next.js Discord

Discord Forum

Add custom data to cookies

Unanswered
Transvaal lion posted this in #help-forum
Open in Discord
Avatar
Transvaal lionOP
import { createMiddlewareClient } from '@supabase/auth-helpers-nextjs'
import { NextResponse } from 'next/server'

import type { NextRequest } from 'next/server'

export async function middleware(req: NextRequest) {
  const res = NextResponse.next()
  const supabase = createMiddlewareClient({ req, res })
  await supabase.auth.getSession()

  return res
}


Hello. This is my middleware for Supabase Auth.
But this misses all the stripe data I added to the auto-generated fields in the DB.

Is there a way to add those to the cookies?

Eg. here's how I use the auth:

import { createServerComponentClient } from "@supabase/auth-helpers-nextjs";
import { cookies } from "next/headers";
import Generate from "@/components/Generate";
import Link from "next/link";
import "../../(public)/globals.css";

export default async function Index() {
    const supabase = createServerComponentClient({ cookies });

    const {
        data: { user },
    } = await supabase.auth.getUser();

    return (
        <div
            style={{
                display: "flex",
                justifyContent: "center",
                alignItems: "center",
                height: "100vh",
                width: "60vw",
            }}
        >
            <div>
                <h1 className="text-2xl font-bold text-center">sync. labs</h1>

                {user ? (
                    <div className="mt-4">
                        {JSON.stringify(user.user_metadata)}
                    </div>
                ) : (
                    <div className="mt-4">
                        <Link href="/login">Please login to continue</Link>
                    </div>
                )}
            </div>
        </div>
    );
}

1 Reply

Avatar
Transvaal lionOP
Going with a other fix now