roque
roque
BABetter Auth
Created by invocation97 on 2/7/2025 in #help
listUsers returns status 401 UNAUTHORIZED even though the current user is an admin.
Got it, thanks so much for sharing with me! 😃 Your approach fits much better, taking advantage of the speed of Next.js I have an admin authentication form that creates the user and is displayed in that list. For the authentication, I'm using authClient.admin.createUser and router.fresh which refreshes the page. And for the list, I'm using your approach with auth.api.listUsers. I thought I could use authClient.admin for everything just for the actions and admin pages. But by using that, I'd have to use ‘use client’ and wouldn't take advantage of the power of Next.js, right?
11 replies
BABetter Auth
Created by invocation97 on 2/7/2025 in #help
listUsers returns status 401 UNAUTHORIZED even though the current user is an admin.
@invocation97
11 replies
BABetter Auth
Created by invocation97 on 2/7/2025 in #help
listUsers returns status 401 UNAUTHORIZED even though the current user is an admin.
Hi! I did something like this: "use client"; import { authClient } from "@/lib/auth-client"; import React, { useEffect, useState } from "react"; import { Table, TableBody, TableCaption, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; interface User { id: string; name: string; email: string; emailVerified: boolean; createdAt: string; updatedAt: string; role: string; } export default function ListAdm() { const [users, setUsers] = useState<User[]>([]); useEffect(() => { async function fetchUsers() { const response: any = await authClient.admin.listUsers({ query: { limit: 100 }, }); setUsers(response.data.users); } fetchUsers(); }, []); if (!users || users.length === 0) { return ( <div className="space-y-4"> <p>No users found.</p> </div> ); } return ( <> <Table> <TableCaption>Lista de usuários</TableCaption> <TableHeader> <TableRow> <TableHead className="w-[100px]">Nome</TableHead> <TableHead className="w-[100px]">E-mail</TableHead> <TableHead className="text-right">Ação</TableHead> </TableRow> </TableHeader> <TableBody> {users.map((user, index) => ( <TableRow key={index}> <TableCell className="font-medium">{user.name}</TableCell> <TableCell className="font-medium">{user.email}</TableCell> <TableCell className="text-right">BOTAO</TableCell> </TableRow> ))} </TableBody> </Table> </> ); } I'm using authClient.admin.listUsers instead of using auth.api.listUsers. Is this a good way to do it? And I'm thinking how to a get a instant refresh when my auth component creates an user.
11 replies
BABetter Auth
Created by roque on 4/4/2025 in #help
Middleware - Better Auth
I found the issue…it was because my middleware wasnt int the scr folder…sorry For the other question, if I want to protect some routes only for admin, how can I do this? Because I cant get the role with getSessionCookie or getCookieCache
14 replies
BABetter Auth
Created by roque on 4/4/2025 in #help
Middleware - Better Auth
So if its valid…why my middleware isnt working? Do you have any idea
14 replies
BABetter Auth
Created by roque on 4/4/2025 in #help
Middleware - Better Auth
@bekacru
14 replies
BABetter Auth
Created by roque on 4/4/2025 in #help
Middleware - Better Auth
Sorry for any dumb questions, I'm new using auths But in my case, when the user is logged in, I get a better-auth.session_token in the Cookies Browser. Isn't this a valid cookie so the middleware can validate? And I'm also using admin(), nextCookies() for plugins. Should I use betterFetch instead?
14 replies
BABetter Auth
Created by roque on 4/4/2025 in #help
Middleware - Better Auth
In this case
14 replies
BABetter Auth
Created by roque on 4/4/2025 in #help
Middleware - Better Auth
So should I use getCookieCache and something like sessionCookie.session? Or await betterFetch is the better way?
14 replies
BABetter Auth
Created by roque on 2/6/2025 in #help
Resseting password
Omg, my fault! Thanks a lottttt
3 replies