listUsers() supabase auth
Unanswered
California pilchard posted this in #help-forum
California pilchardOP
hi guys
``
export async function getUsers() {
const cookieStore = cookies();
const supabase = await createClient(cookieStore);
const result = await supabase.auth.admin.listUsers();
return result;
}
```
i get this error AuthApiError: User not allowed status:401
any help ?
``
export async function getUsers() {
const cookieStore = cookies();
const supabase = await createClient(cookieStore);
const result = await supabase.auth.admin.listUsers();
return result;
}
```
i get this error AuthApiError: User not allowed status:401
any help ?
12 Replies
I think you should use
@supabase/auth-helpers-nextjsCalifornia pilchardOP
import { createServerClient, type CookieOptions } from '@supabase/ssr'
import { cookies } from 'next/headers'
export const createClient = (cookieStore: ReturnType<typeof cookies>) => {
return createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
.................iam using @supabase/ssr
yes use
@supabase/auth-helpers-nextjsCalifornia pilchardOP
but why ?
will make your life easier
California pilchardOP
😢
or you have to do something like this
const cookieStore = cookies();
const supabase = await createClient();
await supabase.auth.setSession({
refresh_token: cookieStore.get('refreshToken').value,
access_token: cookieStore.get('accessToken').value,
{
auth: { persistSession: false },
}
})
const result = await supabase.auth.admin.listUsers();
return result;not tested but should be simliar
California pilchardOP
@Ray thank i will try it