Skip to content

Commit

Permalink
Remove logging
Browse files Browse the repository at this point in the history
  • Loading branch information
lwjameson committed Jul 15, 2024
1 parent 864173d commit 75cbca8
Showing 1 changed file with 0 additions and 12 deletions.
12 changes: 0 additions & 12 deletions src/pages/api/invite-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,16 @@ const supabaseServerUrl =
const invitesAllowed = import.meta.env.PUBLIC_ENABLE_USER_INVITE;

export const POST: APIRoute = async ({ request, cookies }) => {
console.log('Checking for allowed imports');
// Should this be callable at all?
if (!invitesAllowed) {
console.log('Invites not allowed!');
return new Response(JSON.stringify({ error: 'Unauthorized' }), {
status: 401,
});
}

// Verify if the user is logged in
console.log('verify login');
const supabase = await createSupabaseServerClient(cookies);
if (!supabase) {
console.log('Failed to create client!');
return new Response(JSON.stringify({ error: 'Unauthorized' }), {
status: 401,
});
Expand All @@ -30,11 +26,9 @@ export const POST: APIRoute = async ({ request, cookies }) => {
// User must be an Org Admin to use this endpoint

// Get the user
console.log('Get User');
const userResp = await supabase.auth.getUser();

if (userResp.error) {
console.log('Get User failed!');
return new Response(JSON.stringify({ error: 'Failed to get user' }), {
status: 500,
});
Expand All @@ -45,13 +39,11 @@ export const POST: APIRoute = async ({ request, cookies }) => {
const id = user.user.id;

// Is the user an Org Admin?
console.log('Checking Is org admin');
const orgAdminResp = await supabase.rpc('is_admin_organization', {
user_id: id,
});

if (orgAdminResp.error) {
console.log('org admin check failed: ', orgAdminResp.error);
return new Response(
JSON.stringify({ error: 'Failed to get org admin response' }),
{
Expand All @@ -61,7 +53,6 @@ export const POST: APIRoute = async ({ request, cookies }) => {
}

if (!orgAdminResp.data) {
console.log('');
return new Response(JSON.stringify({ error: 'Unauthorized' }), {
status: 401,
});
Expand All @@ -73,14 +64,11 @@ export const POST: APIRoute = async ({ request, cookies }) => {
import.meta.env.SUPABASE_SERVICE_KEY
);

console.log('Supa: ', supa);
const body = await request.json();

console.log('Email: ', body.email);
const inviteResp = await supa.auth.admin.inviteUserByEmail(body.email);

if (inviteResp.error) {
console.log('Invite error: ', inviteResp.error);
return new Response(JSON.stringify({ error: 'Failed to invite user' }), {
status: 500,
});
Expand Down

0 comments on commit 75cbca8

Please sign in to comment.