fix: auth post (#624)

Co-authored-by: Igor Loskutov <igor.loskutoff@gmail.com>
This commit is contained in:
Igor Monadical
2025-09-09 15:48:07 -04:00
committed by GitHub
parent f81fe9948a
commit cde99ca271
2 changed files with 5 additions and 30 deletions

View File

@@ -2,7 +2,6 @@ from datetime import datetime
from typing import Literal from typing import Literal
import sqlalchemy as sa import sqlalchemy as sa
from fastapi import HTTPException
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
from reflector.db import get_database, metadata from reflector.db import get_database, metadata
@@ -178,23 +177,6 @@ class MeetingController:
return None return None
return Meeting(**result) return Meeting(**result)
async def get_by_id_for_http(self, meeting_id: str, user_id: str | None) -> Meeting:
"""
Get a meeting by ID for HTTP request.
If not found, it will raise a 404 error.
"""
query = meetings.select().where(meetings.c.id == meeting_id)
result = await get_database().fetch_one(query)
if not result:
raise HTTPException(status_code=404, detail="Meeting not found")
meeting = Meeting(**result)
if result["user_id"] != user_id:
meeting.host_room_url = ""
return meeting
async def update_meeting(self, meeting_id: str, **kwargs): async def update_meeting(self, meeting_id: str, **kwargs):
query = meetings.update().where(meetings.c.id == meeting_id).values(**kwargs) query = meetings.update().where(meetings.c.id == meeting_id).values(**kwargs)
await get_database().execute(query) await get_database().execute(query)

View File

@@ -2,12 +2,6 @@
import createClient from "openapi-fetch"; import createClient from "openapi-fetch";
import type { paths } from "../reflector-api"; import type { paths } from "../reflector-api";
import {
queryOptions,
useMutation,
useQuery,
useSuspenseQuery,
} from "@tanstack/react-query";
import createFetchClient from "openapi-react-query"; import createFetchClient from "openapi-react-query";
import { assertExistsAndNonEmptyString } from "./utils"; import { assertExistsAndNonEmptyString } from "./utils";
import { isBuildPhase } from "./next"; import { isBuildPhase } from "./next";
@@ -16,16 +10,11 @@ const API_URL = !isBuildPhase
? assertExistsAndNonEmptyString(process.env.NEXT_PUBLIC_API_URL) ? assertExistsAndNonEmptyString(process.env.NEXT_PUBLIC_API_URL)
: "http://localhost"; : "http://localhost";
// Create the base openapi-fetch client with a default URL
// The actual URL will be set via middleware in AuthProvider
export const client = createClient<paths>({ export const client = createClient<paths>({
baseUrl: API_URL, baseUrl: API_URL,
}); });
export const $api = createFetchClient<paths>(client); // has to be called BEFORE $api is created with createFetchClient<paths>(client) or onRequest doesn't fire [at least for POST]
let currentAuthToken: string | null | undefined = null;
client.use({ client.use({
onRequest({ request }) { onRequest({ request }) {
if (currentAuthToken) { if (currentAuthToken) {
@@ -44,6 +33,10 @@ client.use({
}, },
}); });
export const $api = createFetchClient<paths>(client);
let currentAuthToken: string | null | undefined = null;
// the function contract: lightweight, idempotent // the function contract: lightweight, idempotent
export const configureApiAuth = (token: string | null | undefined) => { export const configureApiAuth = (token: string | null | undefined) => {
currentAuthToken = token; currentAuthToken = token;