SUPABASE & NEXT.JS:
Answered
Pyramid ant posted this in #help-forum
Pyramid antOP
I can't retrive the list of user within the auth.users table using the 'listUsers()' method
async function getUsers() {
const supabase = createServerComponentClient({ cookies }) //conntect to the DB
const { data: { users }, error } = await supabase.auth.admin.listUsers()
if(users){console.log('fetch data: ', users)}
if(error){console.log('fetch error: ', error)}
return users
}12 Replies
Manchester Terrier
What error do you get?
Pyramid antOP
I get an empty array (which i know shouldn't be so ), and this:
fetch data: []
fetch error: AuthApiError: User not allowed
fetch data: []
fetch error: AuthApiError: User not allowed
Manchester Terrier
Are you using your service_role key?
Answer
Pyramid antOP
super, sounds like it should be the reason... let me give it a try, will let you know! tks mate
@Manchester Terrier Are you using your service_role key?
Pyramid antOP
it works my friend!!!
Manchester Terrier
Happy to hear that!
Pyramid antOP
full code below for passionated 😉
import Link from 'next/link'
import { cookies } from 'next/headers'
import { createServerComponentClient } from '@supabase/auth-helpers-nextjs'
import { createClient } from '@supabase/supabase-js'
// SUPABASE admin privilage
const dotenv = require('dotenv');
dotenv.config({ path: '.env.local' });
const supabase_url = process.env.NEXT_PUBLIC_SUPABASE_URL;
const service_role_key = process.env.NEXT_SERVICE_ROLE_KEY;
const supabase = createClient(supabase_url, service_role_key, {
auth: {
autoRefreshToken: false,
persistSession: false
}
});
// Access auth admin api
const adminAuthClient = supabase.auth.admin
async function getUsers() {
const supabase = createServerComponentClient({ cookies }) //conntect to the DB
const { data: { users }, error } = await adminAuthClient.listUsers()
if(users){console.log('fetch data: ', users)}
if(error){console.log('fetch error: ', error)}
return users
}Original message was deleted
Manchester Terrier
Don't forget to mark a message as the answer for your post!
Pyramid antOP
what does it meas? is my first ticket here 🙂
Manchester Terrier
So right click on the message containing the solution and then follow the steps in the picture :)
Pyramid antOP
i think i can't do that...