HonoH
Hono9mo ago
nemo

Hono Supabase OAuth Error

Hi! I am trying to implement OAuth with Supabase in my Hono application. This is a server-side API client and I want to get access to the session of the user. Right now I am doing something like this:
import { Hono } from "hono";
import { getSupabase } from "../middlewares/supabase";
import { envs } from "../config/envs";

const auth = new Hono();

auth.get("/oauth/google", async (context) => {
  const supabase = getSupabase(context);

  const { data, error } = await supabase.auth.signInWithOAuth({
    provider: "google",
    options: {
      redirectTo: `${envs.authServiceUrl}/auth/oauth/google/callback`,
    },
  });

  context.status(301);
  context.json({ data, error });
});

auth.get("/oauth/google/callback", async (c) => {
  const supabase = getSupabase(c);
  const { data, error } = await supabase.auth.getSession();
  const { session } = data;

  if (error) {
    return c.json({ error: error.message }, 400);
  }

  return c.json({
    message: "User session retrieved successfully",
    session,
  });
});

export default auth;


And the middleware is this: https://gist.github.com/nemo0/4ffcbc72b8b9005cf0f067b06a7acb86

But, I am getting errors like the image attached. Can someone guide me on what I am doing wrong, please?
image.png
Was this page helpful?