Fix errors

This commit is contained in:
Arthur Belleville 2025-06-24 21:20:24 +02:00
parent 59cd45c689
commit fa90dd61f5
No known key found for this signature in database
5 changed files with 28 additions and 22 deletions

View file

@ -22,7 +22,6 @@ userRouter.get("/get-stream-token", async (c) => {
disableCache: true,
}
);
console.log({ user_id });
const token = serverClient.createToken(user_id);
return c.json({

View file

@ -0,0 +1,10 @@
export const LoadingSpinner = () => {
return (
<div className="flex items-center justify-center min-h-screen">
<div
role="status"
className="animate-spin rounded-full h-16 w-16 border-t-2 border-b-2 border-emerald-500"
/>
</div>
);
};

View file

@ -2,6 +2,7 @@ import { useEffect, useState } from "react";
import { Navigate, Outlet } from "react-router-dom";
import { match } from "ts-pattern";
import { useSession } from "@ui/contexts/SessionContext";
import { LoadingSpinner } from "./LoadingSpinner";
interface ProtectedRouteProps {
fallback?: string;
@ -9,7 +10,6 @@ interface ProtectedRouteProps {
export const ProtectedRoute = ({ fallback }: ProtectedRouteProps) => {
const { session } = useSession();
console.log({ session });
const [isLoading, setIsLoading] = useState(true);
useEffect(() => {
@ -41,16 +41,7 @@ export const ProtectedRoute = ({ fallback }: ProtectedRouteProps) => {
return (
<>
{match(status)
.with("loading", () => (
<div>
<div className="flex items-center justify-center min-h-screen">
<div
role="status"
className="animate-spin rounded-full h-16 w-16 border-t-2 border-b-2 border-emerald-500"
/>
</div>
</div>
))
.with("loading", () => <LoadingSpinner />)
.with("should-land-user", () => <Navigate to="/landing" replace />)
.with("should-redirect", () => (
<Navigate to={fallback ?? "/login"} replace />

View file

@ -45,7 +45,7 @@ describe("SignOutButton", () => {
renderWithRouter(<SignOutButton />);
// Click the button
fireEvent.click(screen.getByRole("button", { name: /Déconnexion/i }));
fireEvent.click(screen.getByRole("button", { name: /Se déconnecter/i }));
// Check if logout was called
expect(mockLogout).toHaveBeenCalled();

View file

@ -5,6 +5,7 @@ import { useQuery } from "@tanstack/react-query";
import { Tables } from "@ui/types/database.types";
import { useSession } from "@ui/contexts/SessionContext";
import { api } from "@ui/lib/api";
import { LoadingSpinner } from "@ui/components/LoadingSpinner";
type User = Tables<"profiles"> & {
streamToken: string | null;
@ -23,14 +24,19 @@ export const UserStoreProvider = ({
queryFn: async () => {
const { data, error } = await supabase.from("profiles").select("*");
if (error) throw error;
const {
data: { token },
} = await api.get("/api/v1/users/get-stream-token", {
headers: {
Authorization: `Bearer ${session?.access_token}`,
},
});
console.log({ token, data });
let token = null;
try {
const {
data: { token: streamToken },
} = await api.get("/api/v1/users/get-stream-token", {
headers: {
Authorization: `Bearer ${session?.access_token}`,
},
});
token = streamToken;
} catch (error) {
console.error("Failed to get stream token:", error);
}
return {
...data[0],
streamToken: token,
@ -39,7 +45,7 @@ export const UserStoreProvider = ({
});
if (isPending) {
return <div>Loading...</div>;
return <LoadingSpinner />;
}
if (!data) {