Skip to content

Need help with "Store supabase user role using useState in global composable"? #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nuwanvc opened this issue Mar 28, 2023 · 2 comments
Closed
Labels
question Further information is requested Stale

Comments

@nuwanvc
Copy link

nuwanvc commented Mar 28, 2023

Hi,

I'm trying to get the user role from superbase and store it in composable.
I'm Getting error " [nuxt] [useState] key must be a string:"

Any help would be highly appreciated.
Below is the code in composable.

export const useUserRole = function () {
    const user = useSupabaseUser()
    const email = user.value.email
    const client = useSupabaseClient()
    const [role, setRole] = useState('')

    const fetchUserRole = async () => {
        const { data, error } = await client
            .from('people')
            .select('role')
            .eq('email', email)
            .single()

        if (error) {
            console.error(error)
            return
        }

        if (data) {
            setRole(data.role)
        }
    }

    onMounted(fetchUserRole)

    return role
}

@nuwanvc nuwanvc added the question Further information is requested label Mar 28, 2023
Copy link

github-actions bot commented May 6, 2025

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label May 6, 2025
Copy link

github-actions bot commented Jun 5, 2025

This issue was closed because it has been stalled for 30 days with no activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested Stale
Projects
None yet
Development

No branches or pull requests

1 participant