improvement for the backend api
This commit is contained in:
@@ -13,7 +13,7 @@ import React, {
|
||||
} from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { authApi } from "@/lib/api";
|
||||
import { USE_MOCKS } from "@/lib/utils/constants";
|
||||
import { USE_MOCKS, STORAGE_KEYS } from "@/lib/utils/constants";
|
||||
import type { User } from "@/lib/types/api";
|
||||
|
||||
interface AuthContextType {
|
||||
@@ -85,13 +85,28 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
const response = await authApi.complete(token);
|
||||
setUser(response.user);
|
||||
// Exchange token for JWT
|
||||
await authApi.complete(token);
|
||||
|
||||
// Fetch user data with the JWT token
|
||||
if (!USE_MOCKS) {
|
||||
const userData = await authApi.me();
|
||||
setUser(userData);
|
||||
|
||||
// Save user to storage
|
||||
if (typeof window !== "undefined") {
|
||||
localStorage.setItem(STORAGE_KEYS.USER, JSON.stringify(userData));
|
||||
}
|
||||
} else {
|
||||
// For mocks, get user from mock data
|
||||
const userData = authApi.getUserFromStorage();
|
||||
setUser(userData);
|
||||
}
|
||||
|
||||
// Redirect to home
|
||||
router.push("/");
|
||||
} catch (err: any) {
|
||||
const errorMessage = err?.error?.message || "Ошибка авторизации";
|
||||
const errorMessage = err?.detail || err?.error?.message || "Ошибка авторизации";
|
||||
setError(errorMessage);
|
||||
throw err;
|
||||
} finally {
|
||||
|
||||
@@ -143,13 +143,13 @@ export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
|
||||
{user && (
|
||||
<NavUser
|
||||
user={{
|
||||
name: `${user.first_name}${
|
||||
user.last_name ? " " + user.last_name : ""
|
||||
}`,
|
||||
name: user.username || `User ${user.telegram_id}`,
|
||||
email: user.username
|
||||
? `@${user.username}`
|
||||
: `ID: ${user.telegram_id}`,
|
||||
avatar: `https://ui-avatars.com/api/?name=${user.first_name}`,
|
||||
avatar: user.username
|
||||
? `https://ui-avatars.com/api/?name=${user.username}`
|
||||
: `https://ui-avatars.com/api/?name=User`,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
31
components/ui/progress.tsx
Normal file
31
components/ui/progress.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as ProgressPrimitive from "@radix-ui/react-progress"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Progress({
|
||||
className,
|
||||
value,
|
||||
...props
|
||||
}: React.ComponentProps<typeof ProgressPrimitive.Root>) {
|
||||
return (
|
||||
<ProgressPrimitive.Root
|
||||
data-slot="progress"
|
||||
className={cn(
|
||||
"bg-primary/20 relative h-2 w-full overflow-hidden rounded-full",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ProgressPrimitive.Indicator
|
||||
data-slot="progress-indicator"
|
||||
className="bg-primary h-full w-full flex-1 transition-all"
|
||||
style={{ transform: `translateX(-${100 - (value || 0)}%)` }}
|
||||
/>
|
||||
</ProgressPrimitive.Root>
|
||||
)
|
||||
}
|
||||
|
||||
export { Progress }
|
||||
Reference in New Issue
Block a user