Skip to content

API Reference – vue3-use-authentication

The core hook that provides access to all authentication-related logic.

{
isAuthenticated: Ref<boolean>
user: Ref<User | null>
login: (credentials: LoginPayload) => Promise<void>
logout: () => Promise<void>
refresh: () => Promise<void>
}
  • isAuthenticated – A Ref<boolean> indicating if the user is currently authenticated.
  • user – A Ref<User | null> representing the current user object (or null if not authenticated).
  • login(credentials) – Logs in the user with the provided credentials. Resolves when complete.
  • logout() – Logs out the current user and clears the session.
  • refresh() – Refreshes the user session (e.g., re-fetching or validating the session/token).

import { useAuthentication } from '@resourge/vue3-use-authentication'
const { isAuthenticated, user, login, logout, refresh } = useAuthentication()
watchEffect(() => {
if (isAuthenticated.value) {
console.log('User is logged in as', user.value?.name)
}
})

interface LoginPayload {
username: string
password: string
}
interface User {
id: string
name: string
email?: string
[key: string]: unknown
}