@authopia/sdk v0.6.8
Authopia SDK
Authopia SDK is a lightweight and secure library that simplifies the process of implementing authentication in web applications using passkeys. This SDK provides developers with the necessary tools to easily integrate passkey-based authentication methods into their JavaScript applications, ensuring a secure and seamless user experience.
Installation
You can install the SDK via npm:
npm install @authopia/sdk --save
Alternatively, you can include the script directly in your HTML:
<script src="path/to/authopia-sdk.js"></script>
Usage
1.Initialize the SDK
Before using the SDK, you need to initialize it with your API server's URL:
import { authopiaSdk } from '@authopia/sdk';
const sdk = authopiaSdk({ projectId: 'PROJECT_ID' });
2.Flows
The sdk provides 3 methods: login
, register
and logout
.
sdk.login
.webauthn('user@example.com')
.then(user => {
// User logged in successfully, handle the user object
console.log('Logged in user:', user);
})
.catch(error => {
// Handle login error
console.error('Login failed:', error);
});
The package also provides a helper function to check if user is logged in locally.
import { isLocallyAuthenticated } from '@authopia/sdk';
if (!isLocallyAuthenticated()) {
// show authentication flows
}
Error Handling
The SDK returns promises for all authentication actions, allowing you to handle success and failure cases effectively. Make sure to handle errors gracefully to provide a smooth user experience.
Security
Authopia Passkeys SDK is designed with security in mind. It uses passkeys for authentication, which enhances security by eliminating the need to send plaintext passwords over the network.
However, security is a shared responsibility, and you must also ensure that your server-side infrastructure is properly secured and follows best practices for handling user data.
Thank you for using Authopia Passkeys SDK! We hope it simplifies the authentication process and improves the security of your web application.