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;
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;