# @gopasswordless/sdk

> GoPasswordless SDK

Latest version **2.3.0** (published 2024-03-21) · ISC license · 0 weekly downloads

## Install

```sh
npm install @gopasswordless/sdk
pnpm add @gopasswordless/sdk
yarn add @gopasswordless/sdk
bun add @gopasswordless/sdk
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.3.0 |
| Published | 2024-03-21 |
| First published | 2023-11-05 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 8 |
| Unpacked size | 258.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | gopasswordless |

## Links

- npm: https://www.npmjs.com/package/@gopasswordless/sdk
- Repository: https://github.com/gopasswordless/sdk
- Homepage: https://github.com/gopasswordless/sdk#readme
- Issues: https://github.com/gopasswordless/sdk/issues
- npm.io page: https://npm.io/package/@gopasswordless/sdk

## Dependencies (8)

- [jose](https://npm.io/package/jose.md) ^5.0.1
- [vaul](https://npm.io/package/vaul.md) ^0.9.0
- [axios](https://npm.io/package/axios.md) ^1.6.0
- [react](https://npm.io/package/react.md) ^18.2.0
- [react-shadow](https://npm.io/package/react-shadow.md) ^20.4.0
- [styled-components](https://npm.io/package/styled-components.md) ^6.1.8
- [@radix-ui/react-icons](https://npm.io/package/@radix-ui/react-icons.md) ^1.3.0
- [@simplewebauthn/browser](https://npm.io/package/@simplewebauthn/browser.md) ^8.3.4

## Recent versions

- 2.3.0 (latest) — 2024-03-21
- 2.2.0 — 2024-03-21
- 2.1.2 — 2024-03-21
- 2.1.1 — 2024-03-11
- 2.1.0 — 2024-02-24
- 2.0.4 — 2024-02-13
- 2.0.3 — 2024-02-12
- 2.0.2 — 2024-02-11
- 2.0.1 — 2024-02-07
- 2.0.0 — 2024-02-07
- 1.4.0 — 2024-01-23
- 1.3.8 — 2024-01-17
- 1.3.7 — 2024-01-17
- 1.3.6 — 2024-01-16
- 1.3.5 — 2024-01-13
- … 28 more at https://npm.io/package/@gopasswordless/sdk/versions

## README

# GoPasswordless SDK

GoPasswordless SDK

[![npm version](https://badge.fury.io/js/%40gopasswordless%2Fsdk.svg)](https://badge.fury.io/js/%40gopasswordless%2Fsdk)

## Overview

The GoPasswordless SDK is a library for implementing passwordless user authentication in javacript/typescript web applications. It provides a modal interface for users to sign up and log in without traditional passwords. The library is built on top of the [WebAuthn API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Authentication_API) and is compatible with most modern browsers. Lower level functions are also exposed allowing implementation of flows with a custom UI.

## Features

- **Passwordless Authentication**: Allows users to sign up and log in without traditional passwords.
- **Customizable Modal Interface**: Easily integrated into existing web applications, providing a user-friendly modal for authentication processes.
- **Event Callbacks**: Handlers for successful signups and logins, providing access tokens for further actions.

## Getting Started

### Installation

Using npm:

```bash
npm install --save @gopasswordless/sdk
```

Using yarn:

```bash
yarn add @gopasswordless/sdk
```

## Usage

### GoPasswordless Configuration

Create an app and get your app ID from [GoPasswordless](https://gopasswordless.dev) (free).

### In React Apps

#### Import the `GoPasswordlessComponent`:

```typescript
import { GoPasswordlessComponent } from "@gopasswordless/sdk";
```

#### Use the `GoPasswordlessComponent` in your app:

```typescript
<GoPasswordlessComponent
  appId="YOUR_GOPASSWORDLESS_APP_ID"
  appName="YOUR_APP_NAME"
  appLogo="YOUR_APP_LOGO_URL"
  screen="signup"
  onSignupCompleted={({ accessToken }) => handleSuccess(accessToken)}
  onLoginSuccess={({ accessToken }) => handleSuccess(accessToken)}
/>
```

### Other JavaScript/Typescript Apps

#### Import the library functions into your project

The functions will handle all of the `WebAuthn` requests (clientside Passkey generation) and `GoPasswordless` API calls for you.

```javascript
import {
  beginRegistration,
  completeRegistration,
  login,
  resendVerificationCode,
} from "@gopasswordless/sdk";
```

#### User Signup

You can get a signup token for a user by passing your GoPasswordless App Id and the user's username to the `beginRegistration` function.

```javascript
const signupToken = await beginRegistration(
  "<YOUR_GOPASSWORDLESS_APP_ID>",
  "<USERNAME>"
);
```

The user will receive a verification code via email or SMS. Have the user input this code and then call the `completeRegistration` function with the verification code and the signup token from the previous step.

```javascript
const { accessToken } = await completeRegistration(
  "<YOUR_GOPASSWORDLESS_APP_ID>",
  "<USERNAME>",
  "<VERIFICATION_CODE>",
  "<SIGNUP_TOKEN>"
);
```

#### User Login

You can get an access token for a user by passing your GoPasswordless App Id and the user's username to the `login` function.

```javascript
const { accessToken } = await login(
  "<YOUR_GOPASSWORDLESS_APP_ID>",
  "<USERNAME>"
);
```

### Validate the Access Token (Serverside)

Import the validate function.

```javascript
import { validate } from "@gopasswordless/sdk";
```

Call the `validate` function with your GoPasswordless App Id and the access token to get the user's claims. The `validate` function will return the user's claims if the token is valid, otherwise it will throw an error.

```javascript
const userClaims = await validate("<YOUR_GOPASSWORDLESS_APP_ID>", "<TOKEN>");
```

## Licence

This project is licensed under the MIT license. See the LICENSE file for more info.

---
_Source: https://npm.io/package/@gopasswordless/sdk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
