chore(frontend): use uuidv7 for auth ids
This commit is contained in:
parent
2208d559e9
commit
81fe27d182
4 changed files with 10 additions and 7 deletions
3
saveinmed-frontend/package-lock.json
generated
3
saveinmed-frontend/package-lock.json
generated
|
|
@ -24,7 +24,8 @@
|
|||
"react-chartjs-2": "^5.3.0",
|
||||
"react-dom": "^19.0.0",
|
||||
"react-hot-toast": "^2.6.0",
|
||||
"resend": "^6.4.2"
|
||||
"resend": "^6.4.2",
|
||||
"uuid": "^10.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/eslintrc": "^3",
|
||||
|
|
|
|||
|
|
@ -25,7 +25,8 @@
|
|||
"react-chartjs-2": "^5.3.0",
|
||||
"react-dom": "^19.0.0",
|
||||
"react-hot-toast": "^2.6.0",
|
||||
"resend": "^6.4.2"
|
||||
"resend": "^6.4.2",
|
||||
"uuid": "^10.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/eslintrc": "^3",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { Client, Databases, Query } from "appwrite";
|
||||
import { v7 as uuidv7 } from "uuid";
|
||||
import { UserRole } from "@/types/auth";
|
||||
|
||||
export const runtime = "edge";
|
||||
|
|
@ -123,9 +124,7 @@ export async function POST(request: NextRequest) {
|
|||
|
||||
// Criar conta no Appwrite Auth (isso precisaria ser feito via SDK de servidor)
|
||||
// Por enquanto, vamos simular a criação retornando um ID único
|
||||
const authId = `user_${Date.now()}_${Math.random()
|
||||
.toString(36)
|
||||
.substr(2, 9)}`;
|
||||
const authId = `user_${uuidv7()}`;
|
||||
|
||||
// Preparar dados do usuário
|
||||
const usuarioData = {
|
||||
|
|
|
|||
|
|
@ -40,7 +40,9 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
|
|||
const storedUser = localStorage.getItem('user');
|
||||
if (storedUser) {
|
||||
try {
|
||||
setUser(JSON.parse(storedUser));
|
||||
const parsedUser = JSON.parse(storedUser) as UserData;
|
||||
setUser(parsedUser);
|
||||
setUserRole(parsedUser.nivel ?? null);
|
||||
} catch (e) {
|
||||
console.error("Erro ao fazer parse do usuário:", e);
|
||||
// Opcional: tentar buscar da API se o parse falhar ou se não tiver no storage
|
||||
|
|
@ -80,4 +82,4 @@ export const useAuth = () => {
|
|||
throw new Error("useAuth deve ser usado dentro de um AuthProvider");
|
||||
}
|
||||
return context;
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue