const app = new Hono();
app.use('*', supabaseMiddleware());
app.get(
'/auth/signinwithgithub',
async (c) => {
const supabase = getSupabase(c);
const { data, error } = await supabase.auth.signInWithOAuth({
provider: 'github',
options: {
redirectTo: 'http://localhost:5173/api/v2/auth/oauth/github/callback'
}
});
if (data.url) {
return c.json({ success: true, url: data.url });
}
return c.json({
message: 'An error occurred. Cannot log you in.'
});
})
.get('/auth/oauth/github/callback', async (c) => {
const code = c.req.query('code');
if (!code) {
return c.json({ error: 'Authorization code is missing' }, 400);
}
const supabase = getSupabase(c);
const { data, error } = await supabase.auth.exchangeCodeForSession(code);
const { session } = data;
if (error) {
return c.json({ error: error.message }, 400);
}
return c.json({
message: 'User session retrieved successfully',
session
});
});
const app = new Hono();
app.use('*', supabaseMiddleware());
app.get(
'/auth/signinwithgithub',
async (c) => {
const supabase = getSupabase(c);
const { data, error } = await supabase.auth.signInWithOAuth({
provider: 'github',
options: {
redirectTo: 'http://localhost:5173/api/v2/auth/oauth/github/callback'
}
});
if (data.url) {
return c.json({ success: true, url: data.url });
}
return c.json({
message: 'An error occurred. Cannot log you in.'
});
})
.get('/auth/oauth/github/callback', async (c) => {
const code = c.req.query('code');
if (!code) {
return c.json({ error: 'Authorization code is missing' }, 400);
}
const supabase = getSupabase(c);
const { data, error } = await supabase.auth.exchangeCodeForSession(code);
const { session } = data;
if (error) {
return c.json({ error: error.message }, 400);
}
return c.json({
message: 'User session retrieved successfully',
session
});
});