0.9.4 • Published 8 months ago

@passageidentity/passage-react v0.9.4

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

passage-react

NPM Version NPM Type Definitions NPM License React Static Badge

About

Passage by 1Password unlocks the passwordless future with a simpler, more secure passkey authentication experience. Passage handles the complexities of the WebAuthn API, and allows you to implement passkeys with ease.

Use Passkey Flex to add passkeys to an existing authentication experience.

Use Passkey Complete as a standalone passwordless auth solution.

Use Passkey Ready to determine if your users are ready for passkeys.

In passage-react

Passage-React the easiest way to use Passage Passkey Complete in your React application. Passage-React provides native react integration with the Passage elements, modular components that provides complete UI/UX for modern authentication, embedded directly into your website.

What's Included?

šŸ™† User login, registration, and profile cross-platform elements.

šŸŽØ Complete UI/UX for all device types and auth flows – in other words, it just works.

šŸ”’ Full passkey authentication.

✨ Magic Link and One-Time Passcodes over email or SMS.

šŸ‘„ Authentication with Social providers.

ProductCompatible
Passkey Flex Passkey Flexāœ–ļø For Passkey Flex, check out passage-flex-js
Passkey Complete Passkey Completeāœ…
Passkey Ready Passkey Readyāœ–ļø For Passkey Ready, check out Authentikit

Getting Started

Check Prerequisites

Install

npm i @passageidentity/passage-react

Configure passage-react in your React application

Configure passage-react by wrapping your application with a PassageProvider

  1. Import the PassageProvider
  2. Wrap your application code with the PassageProvider
    • Pass your Passage app id to the PassageProvider
// src/index.tsx
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';

// Import the PassageProvider
import { PassageProvider } from '@passageidentity/passage-react';

ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
    <React.StrictMode>
        // Wrap your application code with PassageProvider // providing your Passage app id
        <PassageProvider appId='YOUR_PASSAGE_APP_ID'>
            <App />
        </PassageProvider>
    </React.StrictMode>,
);

Add a login or register component

In your application use one of the Passage Authentication components to display a login form for your users.

// src/login.tsx
import React from 'react';
import { PassageAuth } from '@passageidentity/passage-react';

export const LoginPage: React.FC = () => {
    return (
        <>
            <PassageAuth />
        </>
    );
};

Support & Feedback

We are here to help! Find additional docs, the best ways to get in touch with our team, and more within our support resources.


API Reference

Configuration Components

PassageProvider

The PassageProvider component wraps your application to provide the configuration for other Passage Components.

// Import the PassageProvider
import { PassageProvider } from '@passageidentity/passage-react';

<PassageProvider appId='YOUR_PASSAGE_APP_ID'>
    <App />
</PassageProvider>;

Props

NameRequiredTypeDescription
appIdYesstringYour Passage app id.
defaultCountryCodeNostringISO Country code
langNostringDefault language
theme (deprecated)NoPassageThemePropsPassage Theme, theme is deprecated, use the new lightTheme and darkTheme properties instead. Theme will apply a light theme.
lightThemeNoPassageThemePropsPassage Theme
darkThemeNoPassageThemePropsPassage Theme

Authentication/Registration Components

PassageAuth

Renders the passage-auth element.

// src/login.tsx
import React from 'react';
import { PassageAuth } from '@passageidentity/passage-react';

export const AuthPage: React.FC = () => {
    return (
        <>
            <h1>Example Login or Register Page</h1>
            <PassageAuth />
        </>
    );
};

Props

NameRequiredTypeDescription
appIdNo*stringYour Passage app id.
defaultCountryCodeNo*stringISO Country code
langNo*stringDefault language
beforeAuthNoBeforeAuthCallbackMethod to call before authentication
onSuccessNoOnSuccessCallbackMethod to call on authentication success
tokenStoreNoTokenStoreCustom token store instance
themeNo"light", "dark", "auto"Use a light, dark, or auto theme

Note: If not using the PassageProvider the appId property is required. If using the PassageProvider appId, defaultCountryCode, and lang props will be loaded from the PassageProvider but if passed in will override the values for this component instance only.

PassageRegister

Renders the passage-register element.

// src/login.tsx
import React from 'react';
import { PassageRegister } from '@passageidentity/passage-react';

export const RegisterPage: React.FC = () => {
    return (
        <>
            <h1>Example Register Page</h1>
            <PassageRegister />
        </>
    );
};

Props

NameRequiredTypeDescription
appIdNo*stringYour Passage app id.
defaultCountryCodeNo*stringISO Country code
langNo*stringDefault language
beforeAuthNoBeforeAuthCallbackMethod to call before authentication
onSuccessNoOnSuccessCallbackMethod to call on authentication success
tokenStoreNoTokenStoreCustom token store instance
themeNo"light", "dark", "auto"Use a light, dark, or auto theme

Note: If not using the PassageProvider the appId property is required. If using the PassageProvider appId, defaultCountryCode, and lang props will be loaded from the PassageProvider but if passed in will override the values for this component instance only.

PassageLogin

Renders the passage-login element.

// src/login.tsx
import React from 'react';
import { PassageLogin } from '@passageidentity/passage-react';

export const LoginPage: React.FC = () => {
    return (
        <>
            <h1>Example Login Page</h1>
            <PassageLogin />
        </>
    );
};

Props

NameRequiredTypeDescription
appIdNo*stringYour Passage app id.
defaultCountryCodeNo*stringISO Country code
langNo*stringDefault language
beforeAuthNoBeforeAuthCallbackMethod to call before authentication
onSuccessNoOnSuccessCallbackMethod to call on authentication success
tokenStoreNoTokenStoreCustom token store instance
themeNo"light", "dark", "auto"Use a light, dark, or auto theme

Note: If not using the PassageProvider the appId property is required. If using the PassageProvider appId, defaultCountryCode, and lang props will be loaded from the PassageProvider but if passed in will override the values for this component instance only.

User Components

PassageProfile

Renders the passage-profile element.

// src/login.tsx
import React from 'react';
import { PassageProfile } from '@passageidentity/passage-react';

export const ProfilePage: React.FC = () => {
    return (
        <>
            <h1>Example Profile Page</h1>
            <PassageProfile />
        </>
    );
};

Props

NameRequiredTypeDescription
appIdNo*stringYour Passage app id.
defaultCountryCodeNo*stringISO Country code
langNo*stringDefault language
tokenStoreNoTokenStoreCustom token store instance
themeNo"light", "dark", "auto"Use a light, dark, or auto theme

Note: If not using the PassageProvider the appId property is required. If using the PassageProvider appId, defaultCountryCode, and lang props will be loaded from the PassageProvider but if passed in will override the values for this component instance only.

PassagePasskeyTable

Renders the passage-passkey-table element.

// src/login.tsx
import React from 'react';
import { PassagePasskeyTable } from '@passageidentity/passage-react';

export const PasskeyTablePage: React.FC = () => {
    return (
        <>
            <h1>Example Passkey Table Page</h1>
            <PassagePasskeyTable />
        </>
    );
};

Props

NameRequiredTypeDescription
appIdNo*stringYour Passage app id.
defaultCountryCodeNo*stringISO Country code
langNo*stringDefault language
tokenStoreNoTokenStoreCustom token store instance
themeNo"light", "dark", "auto"Use a light, dark, or auto theme

Note: If not using the PassageProvider the appId property is required. If using the PassageProvider appId, defaultCountryCode, and lang props will be loaded from the PassageProvider but if passed in will override the values for this component instance only.

Guard Components

PassageAuthGuard

Protects content by requiring a logged in user to view the content.

A component can be passed in which will render when the user has not been authenticated. The default is to render null.

// src/login.tsx
import React from 'react';
import { PassageAuthGuard } from '@passageidentity/passage-react';

export const ProtectedPage: React.FC = () => {
    return (
        <PassageAuthGuard>
            <p>Protected content</p>
        </PassageAuthGuard>
    );
};

Props

NameRequiredTypeDescription
unAuthCompNoReact.ReactNodeComponent to render if the user is not authenticated

PassageUnAuthGuard

The opposite of PassageAuthGuard ensures a user is NOT authenticated to view the content.

A component can be passed in which will render when the user is authenticated. The default is to render null.

// src/login.tsx
import React from 'react';
import { PassageUnAuthGuard } from '@passageidentity/passage-react';

export const UnAuthOnlyPage: React.FC = () => {
    return (
        <PassageUnAuthGuard>
            <p>Protected content</p>
        </PassageUnAuthGuard>
    );
};

Props

NameRequiredTypeDescription
authCompNoReact.ReactNodeComponent to render if the user is authenticated

Styling Components

PassageTheme (Deprecated)

Note: PassageTheme has been deprecated. Use the PassageLightTheme or PassageDarkTheme components instead. PassageTheme will now apply a Light theme.

The PassageTheme component can customize the look and feel of the Passage Element to match your brand.

// src/login.tsx
import React from 'react';
import { PassageAuth, PassageTheme } from '@passageidentity/passage-react';

export const RegisterPage: React.FC = () => {
    return (
        <>
            <h1>Example Register Page</h1>
            <PassageTheme primaryColor="#ff0000">
                <PassageRegister />
            </PassageTheme>
        </>
    );
};

Props

NameRequiredTypeDefault Value
bodyFontFamilyNostring'Helvetica', BlinkMacSystemFont, -apple-system, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif
headerFontFamilyNostring'Helvetica', BlinkMacSystemFont, -apple-system, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif
containerBackgroundColorNostring#fff
containerMaxWidthNostring300px
containerMarginNostringauto
containerPaddingNostring30px 30px 20px
errorColorNostring#dd0031
bodyFontSizeNostring14px
bodyFontWeightNostring400
bodyTextColorNostring#000
headerFontSizeNostring24px
headerFontWeightNostring700
headerTextColorNostring#000
anchorTextColorNostring#000
anchorHoverColorNostring#4d4d4d
anchorActiveColorNostring#6b6b6b
otpInputBackgroundColorNostring#fff
inputTextColorNostring#000
inputBoxBackgroundColorNostring#fff
inputBoxBorderRadiusNostring5px
checkboxBackgroundColorNostring#000
checkboxTextColorNostring#fff
controlBorderRadiusNostring5px
controlBorderColorNostring#d7d7d7
controlBorderActiveColorNostring#000
buttonFontSizeNostring16px
buttonFontWeightNostring400
buttonWidthNostring50%
primaryButtonBackgroundColorNostring#000
primaryButtonTextColorNostring#fff
primaryButtonBorderRadiusNostring5px
primaryButtonBorderColorNostring#000
primaryButtonBorderWidthNostring0px
primaryButtonBorderHoverColorNostring#000
primaryButtonTextHoverColorNostring#fff
primaryButtonBackgroundHoverColorNostring#4d4d4d
primaryButtonTextActiveColorNostring#fff
primaryButtonBackgroundActiveColorNostring#6b6b6b
primaryButtonBorderActiveColorNostring#000
secondaryButtonBackgroundColorNostring#fff
secondaryButtonTextColorNostring#000
secondaryButtonBorderRadiusNostring5px
secondaryButtonBorderColorNostring#000
secondaryButtonBorderWidthNostring#000
secondaryButtonBorderHoverColorNostring#4d4d4d
secondaryButtonTextHoverColorNostring#000
secondaryButtonBackgroundHoverColorNostring#d7d7d7
secondaryButtonTextActiveColorNostring#000
secondaryButtonBackgroundActiveColorNostring#e0e0e0
secondaryButtonBorderActiveColorNostring#6b6b6b
tableHeaderBorderColorNostring#d7d7d7
tableRowBorderColorNostring#e8e8e8
tablePaginatorSelectedColorNostring#d7d7d7
tablePaginatorHoverColorNostring#e8e8e8
tableDeviceInfoColorDefaultNostring#6b6b6b
tableDeviceIconColorDefaultNostring#6b6b6b
tableActionIconHoverColorDefaultNostring#6b6b6b

PassageLightTheme

The PassageTheme component can customize the look and feel of the Passage Element to match your brand.

// src/login.tsx
import React from 'react';
import { PassageAuth, PassageTheme } from '@passageidentity/passage-react';

export const RegisterPage: React.FC = () => {
    return (
        <>
            <h1>Example Register Page</h1>
            <PassageTheme primaryColor="#ff0000" />
            <PassageRegister />
        </>
    );
};

Props

NameRequiredTypeDefault Value
bodyFontFamilyNostring'Helvetica', BlinkMacSystemFont, -apple-system, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif
headerFontFamilyNostring'Helvetica', BlinkMacSystemFont, -apple-system, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif
containerBackgroundColorNostring#fff
containerMaxWidthNostring300px
containerMarginNostringauto
containerPaddingNostring30px 30px 20px
errorColorNostring#dd0031
bodyFontSizeNostring14px
bodyFontWeightNostring400
bodyTextColorNostring#000
headerFontSizeNostring24px
headerFontWeightNostring700
headerTextColorNostring#000
anchorTextColorNostring#000
anchorHoverColorNostring#4d4d4d
anchorActiveColorNostring#6b6b6b
otpInputBackgroundColorNostring#d7d7d7
inputTextColorNostring#000
inputBoxBackgroundColorNostring#fff
inputBoxBorderRadiusNostring5px
checkboxBackgroundColorNostring#000
checkboxTextColorNostring#fff
controlBorderRadiusNostring5px
controlBorderColorNostring#d7d7d7
controlBorderActiveColorNostring#000
buttonFontSizeNostring16px
buttonFontWeightNostring400
buttonWidthNostring50%
primaryButtonBackgroundColorNostring#000
primaryButtonTextColorNostring#fff
primaryButtonBorderRadiusNostring5px
primaryButtonBorderColorNostring#000
primaryButtonBorderWidthNostring0px
primaryButtonBorderHoverColorNostring#000
primaryButtonTextHoverColorNostring#fff
primaryButtonBackgroundHoverColorNostring#4d4d4d
primaryButtonTextActiveColorNostring#fff
primaryButtonBackgroundActiveColorNostring#6b6b6b
primaryButtonBorderActiveColorNostring#000
secondaryButtonBackgroundColorNostring#fff
secondaryButtonTextColorNostring#000
secondaryButtonBorderRadiusNostring5px
secondaryButtonBorderColorNostring#000
secondaryButtonBorderWidthNostring#000
secondaryButtonBorderHoverColorNostring#4d4d4d
secondaryButtonTextHoverColorNostring#000
secondaryButtonBackgroundHoverColorNostring#d7d7d7
secondaryButtonTextActiveColorNostring#000
secondaryButtonBackgroundActiveColorNostring#e0e0e0
secondaryButtonBorderActiveColorNostring#6b6b6b
tableHeaderBorderColorNostring#d7d7d7
tableRowHoverColorNostring#e0e0e0
tableRowBorderColorNostring#e8e8e8
tablePaginatorSelectedColorNostring#d7d7d7
tablePaginatorHoverColorNostring#e8e8e8

PassageDarkTheme

The PassageTheme component can customize the look and feel of the Passage Element to match your brand.

// src/login.tsx
import React from 'react';
import { PassageAuth, PassageTheme } from '@passageidentity/passage-react';

export const RegisterPage: React.FC = () => {
    return (
        <>
            <h1>Example Register Page</h1>
            <PassageTheme primaryColor="#ff0000" />
            <PassageRegister />
        </>
    );
};

Props

NameRequiredTypeDefault Value
bodyFontFamilyNostring'Helvetica', BlinkMacSystemFont, -apple-system, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif
headerFontFamilyNostring'Helvetica', BlinkMacSystemFont, -apple-system, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif
containerBackgroundColorNostring#fff
containerMaxWidthNostring300px
containerMarginNostringauto
containerPaddingNostring30px 30px 20px
errorColorNostring#dd0031
bodyFontSizeNostring14px
bodyFontWeightNostring400
bodyTextColorNostring#000
headerFontSizeNostring24px
headerFontWeightNostring700
headerTextColorNostring#000
anchorTextColorNostring#000
anchorHoverColorNostring#4d4d4d
anchorActiveColorNostring#6b6b6b
otpInputBackgroundColorNostring#d7d7d7
inputTextColorNostring#000
inputBoxBackgroundColorNostring#fff
inputBoxBorderRadiusNostring5px
checkboxBackgroundColorNostring#000
checkboxTextColorNostring#fff
controlBorderRadiusNostring5px
controlBorderColorNostring#d7d7d7
controlBorderActiveColorNostring#000
buttonFontSizeNostring16px
buttonFontWeightNostring400
buttonWidthNostring50%
primaryButtonBackgroundColorNostring#000
primaryButtonTextColorNostring#fff
primaryButtonBorderRadiusNostring5px
primaryButtonBorderColorNostring#000
primaryButtonBorderWidthNostring0px
primaryButtonBorderHoverColorNostring#000
primaryButtonTextHoverColorNostring#fff
primaryButtonBackgroundHoverColorNostring#4d4d4d
primaryButtonTextActiveColorNostring#fff
primaryButtonBackgroundActiveColorNostring#6b6b6b
primaryButtonBorderActiveColorNostring#000
secondaryButtonBackgroundColorNostring#fff
secondaryButtonTextColorNostring#000
secondaryButtonBorderRadiusNostring5px
secondaryButtonBorderColorNostring#000
secondaryButtonBorderWidthNostring#000
secondaryButtonBorderHoverColorNostring#4d4d4d
secondaryButtonTextHoverColorNostring#000
secondaryButtonBackgroundHoverColorNostring#d7d7d7
secondaryButtonTextActiveColorNostring#000
secondaryButtonBackgroundActiveColorNostring#e0e0e0
secondaryButtonBorderActiveColorNostring#6b6b6b
tableHeaderBorderColorNostring#d7d7d7
tableRowHoverColorNostring#e0e0e0
tableRowBorderColorNostring#e8e8e8
tablePaginatorSelectedColorNostring#d7d7d7
tablePaginatorHoverColorNostring#e8e8e8

Hooks

usePassage

Provides access to the Passage configuration, an instance of passage.js and other Passage functionality.

import { usePassageJS } from '@passageidentity/passage-react';
import { Passage, Session, User } from '@passageidentity/passage-js';

const MyComponent = () => {

    // if using PassageProvider
    const { passageInstance, currentSession, currentUser, appId, lang, defaultCountryCode } =
        usePassageJS();

    // if not useing PassageProvider
    const { passageInstance, currentSession, currentUser, appId, lang, defaultCountryCode } =
        usePassageJS({ appId: 'YOUR_PASSAGE_APP_ID', lang: 'en'', defaultCountryCode: 'us'});

    // other code using data or methods provided by usePassage
};

Parameters

If using the PassageProvider to wrap your app, then you do not need to pass any parameters, unless you want to override a setting for this hook instance only.

NameRequiredTypeDescription
propsNoUsePassageHookPropsPassage Configuration

UsePassageHookProps

NameRequiredTypeDescription
appIdNostringYour Passage app id.
defaultCountryCodeNostringISO Country code
langNostringDefault language
tokenStoreNoTokenStoreCustom token store instance

Returns

NameTypeDescription
appIdstringYour Passage app id.
defaultCountryCodestringISO Country code
langstringDefault language
passageInstancepassage.jsInstance of Passage
getCurrentSessionGetCurrentSessionFnThe current users Passage Session
getCurrentUserGetCurrentUserFnThe current user
signOutPassageSignOutFnMethod than can be called to sign out the current user

Types

BeforeAuthCallback

type BeforeAuthCallback = (email: string) => boolean;

OnSuccessCallback

type OnSuccessCallback = (authResult: authResult) => void;

TokenStore

Learn how to create a custom token store here.

type TokenStore = () => TokenStore;

PassageSignOutFn

type PassageSignOutFn = () => Promise<boolean>;

GetCurrentUserFn

type GetCurrentUserFn = () => User | undefined;

GetCurrentSessionFn

type GetCurrentSessionFn = () => Session | undefined;

PassageThemeProps

interface PassageThemeProps {
    primaryColor?: string;
    containerBackground?: string;
    containerBackgroundColor?: string;
    containerMaxWidth?: string;
    containerMargin?: string;
    containerPadding?: string;
    errorColor?: string;
    bodyFontFamily?: string;
    bodyFontSize?: string;
    bodyFontWeight?: string;
    bodyTextColor?: string;
    headerFontFamily?: string;
    headerFontSize?: string;
    headerFontWeight?: string;
    headerTextColor?: string;
    butonFontSize?: string;
    buttonFontWeight?: string;
    buttonWidth?: string;
    buttonBorderRadius?: string;
    onprimaryColor?: string;
    onHoverColor?: string;
    hoverColor?: string;
    onactiveColor?: string;
    activeColor?: string;
    controlBorderRadius?: string;
    controlBorderColor?: string;
    tableHeaderBorderColor?: string;
    tableRowBorderColor?: string;
    tablePaginatorSelectedColor?: string;
    tablePaginatorHoverColor?: string;
    tableRowBorderColor?: string;
    tablePaginatorSelectedColor?: string;
    tablePaginatorHoverColor?: string;
}
0.9.4

8 months ago

0.9.3

9 months ago

0.9.2

9 months ago

0.9.1

9 months ago

0.9.0

10 months ago

0.8.14

10 months ago

0.8.12

11 months ago

0.8.11

1 year ago

0.8.13

10 months ago

0.8.10

1 year ago

0.8.9

1 year ago

0.8.8

1 year ago

0.8.7

1 year ago

0.8.6

1 year ago

0.8.5

1 year ago

0.8.4

1 year ago

0.8.3

1 year ago

0.8.2

1 year ago

0.8.1

1 year ago

0.8.0

2 years ago

0.7.1

2 years ago

0.7.0

2 years ago

0.6.0

2 years ago

0.5.0

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago