@authyo/auth-vue
v1.0.0
Published
Vue wrapper for the Authyo passwordless SDK.
Downloads
98
Maintainers
Readme
@authyo/auth-vue
Vue 3 wrapper for the Authyo passwordless authentication SDK.
Installation
npm install @authyo/auth-vue @authyo/auth-jsQuick Start
1. Install the Plugin
In your main app file (e.g., main.ts):
import { createApp } from 'vue';
import { AuthyoPlugin } from '@authyo/auth-vue';
import App from './App.vue';
const app = createApp(App);
app.use(AuthyoPlugin, {
clientId: 'YOUR_CLIENT_ID',
clientSecret: 'YOUR_CLIENT_SECRET',
baseUrl: 'https://app.authyo.io' // optional, defaults to https://app.authyo.io
});
app.mount('#app');2. Use in Components
Use the useAuthyo composable in your Vue components:
<template>
<div>
<button @click="sendOtp">Send OTP</button>
<button @click="verifyOtp" :disabled="!otp">Verify OTP</button>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import { useAuthyo } from '@authyo/auth-vue';
const authyo = useAuthyo();
const otp = ref('');
const sendOtp = async () => {
try {
const result = await authyo.sendOtp({
to: '[email protected]',
authWay: 'Email',
otpLength: 6
});
console.log('OTP sent:', result);
} catch (error) {
console.error('Failed to send OTP:', error);
}
};
const verifyOtp = async () => {
try {
const result = await authyo.verifyOtp(otp.value, 'mask-id-from-send-otp');
console.log('OTP verified:', result);
} catch (error) {
console.error('Failed to verify OTP:', error);
}
};
</script>API
useAuthyo()
Returns the AuthyoClient instance. Must be used within a component tree that has AuthyoPlugin installed.
Returns: AuthyoClient
Throws: Error if used outside of AuthyoPlugin setup
AuthyoClient Methods
All methods return Promises that resolve to AuthyoApiEnvelope<T>:
getConfiguration()- Get application customization configurationsendOtp({ to, authWay, otpLength, expiry, deviceInfo })- Send OTP to userverifyOtp(otp, maskId)- Verify OTP codeverifyToken(token)- Verify authentication tokenrevokeSession(token)- Revoke user session
TypeScript Support
This package is written in TypeScript and includes full type definitions.
Requirements
- Vue 3.0+
- @authyo/auth-js 1.0.0+
Documentation
For more information, visit https://authyo.io/docs
License
MIT License
