Skip to content

Commit

Permalink
fix: fixed route
Browse files Browse the repository at this point in the history
  • Loading branch information
MAXOUXAX committed Jan 15, 2024
1 parent d512d00 commit e716aa0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions backend/src/room.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { FastifyRequest } from "fastify";
import { supabase } from "./server";
import { adminSupabase } from "./server";
import { createClient } from "@supabase/supabase-js";

export async function getUserFromRequest(req: any) {
if (!process.env.SUPABASE_URL) {
throw new Error("Missing SUPABASE_URL environment variable");
}

const accesToken = req.cookies.accessToken;
const accessToken = req.cookies.accessToken;
const supabaseUrl = process.env.SUPABASE_URL;
const supabase = createClient(supabaseUrl, accesToken);
const supabase = createClient(supabaseUrl, accessToken);

return await supabase.auth.getUser();
}
Expand All @@ -22,11 +22,13 @@ export async function createRoom(
maxMusicPerUser: number,
maxMusicPerUserDuration: number,
serviceId: string,
req: FastifyRequest,
req: FastifyRequest
) {
let configurationId: string | null = null;
let hostUserProfileId: string | null = null;

const supabase = adminSupabase;

getUserFromRequest(req).then((user) => {
if (user) {
if (user.data.user) hostUserProfileId = user.data.user.id;
Expand Down Expand Up @@ -89,9 +91,8 @@ export async function createRoom(
}

export function endRoom(roomId: string) {
let createdAt: Date | null = null;
let configurationId: string | null = null;
let hostUserProfileId: string | null = null;
let room: any = null;
const supabase = adminSupabase;

supabase
.from("active_rooms")
Expand All @@ -102,9 +103,7 @@ export function endRoom(roomId: string) {
if (res.error) {
return res.error;
} else {
createdAt = res.data[0].created_at;
configurationId = res.data[0].configuration_id;
hostUserProfileId = res.data[0].host_user_profile_id;
room = res.data[0];
console.log("Room ended");
}
});
Expand All @@ -113,9 +112,8 @@ export function endRoom(roomId: string) {
.from("rooms")
.insert([
{
created_at: createdAt,
configuration_id: configurationId,
host_user_profile_id: hostUserProfileId,
...room,
ended_at: new Date(),
},
])
.then((res) => {
Expand Down
Binary file modified backend/src/types/dbTypes.ts
Binary file not shown.

0 comments on commit e716aa0

Please sign in to comment.