Skip to main content

useWeb3Auth

Composable to access the Web3Auth context in Vue.

Import

import { useWeb3Auth } from '@web3auth/modal/vue'

Usage

<script setup lang="ts">
import { useWeb3Auth } from '@web3auth/modal/vue'

const { web3Auth, isConnected, isInitializing, provider, status, initError } = useWeb3Auth()

watchEffect(() => {
if (isConnected.value) {
// User is connected
console.log('Connected with provider:', provider.value)
}
if (isInitializing.value) {
// Web3Auth is initializing
console.log('Web3Auth is initializing')
}
if (provider.value) {
// Web3Auth provider is connected
console.log('Web3Auth provider is connected')
}
if (status.value) {
// Web3Auth status
console.log('Web3Auth status:', status.value)
}
if (initError.value) {
// Web3Auth initialization error
console.log('Web3Auth initialization error:', initError.value)
}
})
</script>

Return Type

import type { IUseWeb3Auth } from '@web3auth/modal/vue'

initError

Ref<Error | null>

Error that occurred during Web3Auth initialization.

isConnected

Ref<boolean>

Whether the user is connected to Web3Auth.

isInitialized

Ref<boolean>

Whether Web3Auth has completed initialization.

isInitializing

Ref<boolean>

Whether Web3Auth is currently initializing.

provider

Ref<IProvider | null>

Connected provider from Web3Auth.

status

Ref<string>

Current status of the Web3Auth connection.

web3Auth

Ref<Web3Auth>

The Web3Auth instance.

getPlugin

(pluginName: PLUGIN_NAME) => IPlugin | null

Helper function to get a plugin by name.