Integration with Scute JS Core
Scute provides a comprehensive authentication solution for web applications through the@scute/js-core package. This guide covers implementing multiple authentication methods including passkeys (WebAuthn), magic links, OTP verification, and OAuth providers. While the examples use React, the same patterns and API calls work with any web framework including Vue, Angular, Svelte, or vanilla JavaScript.
Example Application
A complete working example is available in the Scute JS repository. This example demonstrates all the authentication flows covered in this guide, including:- Multi-method Authentication: Passkey, magic link, OTP, and OAuth sign-in
- Complete User Interface: Forms for each authentication method with proper state management
- Session Management: User profile display with active session management
- Device Registration: WebAuthn device registration flow with skip option
- Error Handling: Comprehensive error handling with user-friendly messages
- URL Management: Proper handling of magic link callbacks and URL cleanup
Prerequisites
- Node.js 16+ and npm/yarn/pnpm
- A Scute application configured in your dashboard
- Basic knowledge of JavaScript/TypeScript and your chosen web framework
Installation
Install the Scute JS Core package:Quick Start
1. Client Configuration
Create a Scute client instance to handle all authentication operations:2. Environment Variables
Configure your environment variables (.env):
Note: TheVITE_prefix is required for Vite-based projects. Adjust the prefix according to your build tool (e.g.,REACT_APP_for Create React App).
3. Basic Authentication Flow
Implement a complete authentication system with state management. The following example uses React, but the same authentication logic applies to any web framework:Authentication Flows
Scute supports three main authentication flows, each designed for different use cases and user preferences. All flows integrate seamlessly with passkey (WebAuthn) authentication when devices are registered.1. Magic Link Flow
The magic link flow allows users to authenticate via email without remembering passwords. When a user enters their email address, a secure magic link is sent to their inbox. Upon clicking the link, they are automatically signed in or signed up if they don’t have an account.Initial Login Attempt
ThesignInOrUp method first attempts passkey authentication. If the user has a registered device, the browser will prompt them to use their passkey instead of sending a magic link. If the user does not have a registered device, the method will send a magic link to the user’s email address:
Sending Magic Links
You can also force sending a magic link regardless of registered devices:Magic Link Confirmation
After sending the magic link, show a confirmation message:Magic Link Verification
When users click the magic link, your application automatically detects and verifies the token:Device Registration
After successful magic link verification, users can be prompted to register their device for future passkey authentication. Users can also be given the option to skip device registration and proceed directly to their profile. This enables passwordless login using WebAuthn for subsequent authentications:2. OTP Flow
The OTP (One-Time Password) flow works with both email addresses and phone numbers. The identifier type can be configured in your Scute dashboard. After entering their identifier, users receive a verification code that must be entered to complete authentication.OTP Verification Form
3. OAuth Flow
The OAuth flow enables users to authenticate through third-party providers like Google. This flow is unique because after successful third-party authentication, Scute redirects back to your application with both a magic link token and a skip parameter.Initiating OAuth Authentication
OAuth Callback Handling
Upon successful authentication with the third-party provider, Scute redirects back to your application with:- A
sct_magicparameter containing the authentication token - A
sct_skparameter that differentiates OAuth magic links from email magic links
sct_sk parameter which you can use to determine the app behaviour based on whether it is an emailed magic link or an OAuth magic link. Below example uses the sct_sk parameter to skip the device registration step for OAuth flows.
sct_sk parameter is OAuth-specific.