forked from RiseUP/riseup-squad21
merge fix
This commit is contained in:
parent
07f6eca41a
commit
65087a9f51
@ -6,6 +6,9 @@ import "./globals.css";
|
||||
import { Toaster } from "@/components/ui/toaster";
|
||||
// [PASSO 1.2] - Importando o nosso provider
|
||||
import { AppointmentsProvider } from "./context/AppointmentsContext";
|
||||
import { AccessibilityProvider } from "./context/AccessibilityContext";
|
||||
import { AccessibilityModal } from "@/components/accessibility-modal";
|
||||
import { ThemeInitializer } from "@/components/theme-initializer";
|
||||
|
||||
export default function RootLayout({
|
||||
children,
|
||||
@ -13,10 +16,14 @@ export default function RootLayout({
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<html lang="en" suppressHydrationWarning>
|
||||
<body className={`font-sans ${GeistSans.variable} ${GeistMono.variable}`}>
|
||||
{/* [PASSO 1.2] - Envolvendo a aplicação com o provider */}
|
||||
<ThemeInitializer />
|
||||
<AccessibilityProvider>
|
||||
<AppointmentsProvider>{children}</AppointmentsProvider>
|
||||
<AccessibilityModal />
|
||||
</AccessibilityProvider>
|
||||
<Analytics />
|
||||
<Toaster />
|
||||
</body>
|
||||
|
||||
@ -1,47 +1,48 @@
|
||||
// Caminho: components/LoginForm.tsx
|
||||
"use client"
|
||||
"use client";
|
||||
|
||||
import type React from "react"
|
||||
import { useState } from "react"
|
||||
import { useRouter } from "next/navigation"
|
||||
import Link from "next/link"
|
||||
import Cookies from "js-cookie"
|
||||
import { jwtDecode } from "jwt-decode"
|
||||
import { cn } from "@/lib/utils"
|
||||
import type React from "react";
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import Link from "next/link";
|
||||
import Cookies from "js-cookie";
|
||||
import { jwtDecode } from "jwt-decode";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
// Componentes Shadcn UI
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { Label } from "@/components/ui/label"
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
||||
import { Separator } from "@/components/ui/separator"
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import { apikey } from "@/services/api.mjs";
|
||||
|
||||
// Hook customizado
|
||||
import { useToast } from "@/hooks/use-toast"
|
||||
import { useToast } from "@/hooks/use-toast";
|
||||
|
||||
// Ícones
|
||||
import { Eye, EyeOff, Mail, Lock, Loader2, UserCheck, Stethoscope, IdCard, Receipt } from "lucide-react"
|
||||
import { Eye, EyeOff, Mail, Lock, Loader2, UserCheck, Stethoscope, IdCard, Receipt } from "lucide-react";
|
||||
|
||||
interface LoginFormProps {
|
||||
title: string
|
||||
description: string
|
||||
role: "secretary" | "doctor" | "patient" | "admin" | "manager" | "finance"
|
||||
themeColor: "blue" | "green" | "orange"
|
||||
redirectPath: string
|
||||
children?: React.ReactNode
|
||||
title: string;
|
||||
description: string;
|
||||
role: "secretary" | "doctor" | "patient" | "admin" | "manager" | "finance";
|
||||
themeColor: "blue" | "green" | "orange";
|
||||
redirectPath: string;
|
||||
children?: React.ReactNode;
|
||||
}
|
||||
|
||||
interface FormState {
|
||||
email: string
|
||||
password: string
|
||||
email: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
// Supondo que o payload do seu token tenha esta estrutura
|
||||
interface DecodedToken {
|
||||
name: string
|
||||
email: string
|
||||
role: string
|
||||
exp: number
|
||||
name: string;
|
||||
email: string;
|
||||
role: string;
|
||||
exp: number;
|
||||
// Adicione outros campos que seu token possa ter
|
||||
}
|
||||
|
||||
@ -67,7 +68,7 @@ const themeClasses = {
|
||||
link: "text-orange-600 hover:text-orange-700",
|
||||
focus: "focus:border-orange-500 focus:ring-orange-500",
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
const roleIcons = {
|
||||
secretary: UserCheck,
|
||||
@ -76,17 +77,17 @@ const roleIcons = {
|
||||
admin: UserCheck,
|
||||
manager: IdCard,
|
||||
finance: Receipt,
|
||||
}
|
||||
};
|
||||
|
||||
export function LoginForm({ title, description, role, themeColor, redirectPath, children }: LoginFormProps) {
|
||||
const [form, setForm] = useState<FormState>({ email: "", password: "" })
|
||||
const [showPassword, setShowPassword] = useState(false)
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
const router = useRouter()
|
||||
const { toast } = useToast()
|
||||
const [form, setForm] = useState<FormState>({ email: "", password: "" });
|
||||
const [showPassword, setShowPassword] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const router = useRouter();
|
||||
const { toast } = useToast();
|
||||
|
||||
const currentTheme = themeClasses[themeColor]
|
||||
const Icon = roleIcons[role]
|
||||
const currentTheme = themeClasses[themeColor];
|
||||
const Icon = roleIcons[role];
|
||||
|
||||
// ==================================================================
|
||||
// AJUSTE PRINCIPAL NA LÓGICA DE LOGIN
|
||||
@ -96,13 +97,12 @@ export function LoginForm({ title, description, role, themeColor, redirectPath,
|
||||
setIsLoading(true);
|
||||
|
||||
const LOGIN_URL = "https://yuanqfswhberkoevtmfr.supabase.co/auth/v1/token?grant_type=password";
|
||||
const API_KEY = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;
|
||||
const API_KEY = apikey;
|
||||
|
||||
if (!API_KEY) {
|
||||
toast({
|
||||
title: "Erro de Configuração",
|
||||
description: "A chave da API não foi encontrada.",
|
||||
variant: "destructive",
|
||||
});
|
||||
setIsLoading(false);
|
||||
return;
|
||||
@ -113,7 +113,7 @@ export function LoginForm({ title, description, role, themeColor, redirectPath,
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"apikey": API_KEY,
|
||||
apikey: API_KEY,
|
||||
},
|
||||
body: JSON.stringify({ email: form.email, password: form.password }),
|
||||
});
|
||||
@ -135,15 +135,14 @@ export function LoginForm({ title, description, role, themeColor, redirectPath,
|
||||
/* ===================================================================================== */
|
||||
|
||||
Cookies.set("access_token", accessToken, { expires: 1, secure: true });
|
||||
localStorage.setItem('user_info', JSON.stringify(user));
|
||||
localStorage.setItem("user_info", JSON.stringify(user));
|
||||
|
||||
toast({
|
||||
title: "Login bem-sucedido!",
|
||||
description: `Bem-vindo(a), ${user.user_metadata.full_name || 'usuário'}! Redirecionando...`,
|
||||
description: `Bem-vindo(a), ${user.user_metadata.full_name || "usuário"}! Redirecionando...`,
|
||||
});
|
||||
|
||||
router.push(redirectPath);
|
||||
|
||||
} catch (error) {
|
||||
toast({
|
||||
title: "Erro no Login",
|
||||
@ -152,7 +151,7 @@ export function LoginForm({ title, description, role, themeColor, redirectPath,
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// O JSX do return permanece exatamente o mesmo, preservando seus ajustes.
|
||||
return (
|
||||
@ -173,38 +172,15 @@ export function LoginForm({ title, description, role, themeColor, redirectPath,
|
||||
<Label htmlFor="email">E-mail</Label>
|
||||
<div className="relative">
|
||||
<Mail className="absolute left-3 top-1/2 -translate-y-1/2 text-gray-400 w-5 h-5" />
|
||||
<Input
|
||||
id="email"
|
||||
type="email"
|
||||
placeholder="seu.email@clinica.com"
|
||||
value={form.email}
|
||||
onChange={(e) => setForm({ ...form, email: e.target.value })}
|
||||
className={cn("pl-11 h-12 border-slate-200", currentTheme.focus)}
|
||||
required
|
||||
disabled={isLoading}
|
||||
/>
|
||||
<Input id="email" type="email" placeholder="seu.email@clinica.com" value={form.email} onChange={(e) => setForm({ ...form, email: e.target.value })} className={cn("pl-11 h-12 border-slate-200", currentTheme.focus)} required disabled={isLoading} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="password">Senha</Label>
|
||||
<div className="relative">
|
||||
<Lock className="absolute left-3 top-1/2 -translate-y-1/2 text-gray-400 w-5 h-5" />
|
||||
<Input
|
||||
id="password"
|
||||
type={showPassword ? "text" : "password"}
|
||||
placeholder="Digite sua senha"
|
||||
value={form.password}
|
||||
onChange={(e) => setForm({ ...form, password: e.target.value })}
|
||||
className={cn("pl-11 pr-12 h-12 border-slate-200", currentTheme.focus)}
|
||||
required
|
||||
disabled={isLoading}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowPassword(!showPassword)}
|
||||
className="absolute right-2 top-1/2 -translate-y-1/2 h-8 w-8 p-0 text-gray-400 hover:text-gray-600"
|
||||
disabled={isLoading}
|
||||
>
|
||||
<Input id="password" type={showPassword ? "text" : "password"} placeholder="Digite sua senha" value={form.password} onChange={(e) => setForm({ ...form, password: e.target.value })} className={cn("pl-11 pr-12 h-12 border-slate-200", currentTheme.focus)} required disabled={isLoading} />
|
||||
<button type="button" onClick={() => setShowPassword(!showPassword)} className="absolute right-2 top-1/2 -translate-y-1/2 h-8 w-8 p-0 text-gray-400 hover:text-gray-600" disabled={isLoading}>
|
||||
{showPassword ? <EyeOff className="w-5 h-5" /> : <Eye className="w-5 h-5" />}
|
||||
</button>
|
||||
</div>
|
||||
@ -243,5 +219,5 @@ export function LoginForm({ title, description, role, themeColor, redirectPath,
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
);
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
|
||||
const BASE_URL = "https://yuanqfswhberkoevtmfr.supabase.co";
|
||||
const API_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inl1YW5xZnN3aGJlcmtvZXZ0bWZyIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTQ5NTQzNjksImV4cCI6MjA3MDUzMDM2OX0.g8Fm4XAvtX46zifBZnYVH4tVuQkqUH6Ia9CXQj4DztQ";
|
||||
export const apikey = API_KEY;
|
||||
var tempToken;
|
||||
|
||||
export async function login() {
|
||||
@ -9,7 +9,7 @@ export async function login() {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Prefer: "return=representation",
|
||||
"apikey": API_KEY, // valor fixo
|
||||
apikey: API_KEY, // valor fixo
|
||||
},
|
||||
body: JSON.stringify({ email: "riseup@popcode.com.br", password: "riseup" }),
|
||||
});
|
||||
@ -21,13 +21,9 @@ export async function login() {
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
let loginPromise = login();
|
||||
|
||||
|
||||
|
||||
async function request(endpoint, options = {}) {
|
||||
|
||||
if (loginPromise) {
|
||||
try {
|
||||
await loginPromise;
|
||||
@ -42,8 +38,8 @@ async function request(endpoint, options = {}) {
|
||||
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
"apikey": API_KEY,
|
||||
...(token ? { "Authorization": `Bearer ${token}` } : {}),
|
||||
apikey: API_KEY,
|
||||
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
||||
...options.headers,
|
||||
};
|
||||
|
||||
@ -54,7 +50,6 @@ async function request(endpoint, options = {}) {
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
|
||||
let errorBody = `Status: ${response.status}`;
|
||||
try {
|
||||
const contentType = response.headers.get("content-type");
|
||||
@ -66,7 +61,6 @@ async function request(endpoint, options = {}) {
|
||||
errorBody = await response.text();
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
errorBody = `Status: ${response.status} - Falha ao ler corpo do erro.`;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user