2.7.0 • Published 3 days ago

@corbado/react v2.7.0

Weekly downloads
-
License
ISC
Repository
github
Last release
3 days ago

@corbado/react

License Documentation Slack npm version


Table of Contents


Overview

The @corbado/react package provides a comprehensive solution for integrating passkey-based authentication in React applications. It simplifies the process of managing authentication states and user sessions with easy-to-use hooks and UI components.


🚀 Getting Started

Prerequisites

  • React v18+
  • Node.js >=18.17.0 or later

Installation

npm install @corbado/react

Setting up the package

Add CorbadoProvider to your main App component to wrap your application:

import { CorbadoProvider } from '@corbado/react';

function App() {
  return (
    <CorbadoProvider projectId='pro-XXXXXXXXXXXXXXXXXXXX'>
      {/* Your routes and other components go here */}
    </CorbadoProvider>
  );
}

export default App;

📌 Usage

CorbadoAuth component

Adding SignUp/Login screens is simple with @corbado/react. The CorbadoAuth component allows your users to sign up and login with their passkeys. Additionally, it provides fallback options like email one-time passcode for users who don't have a passkey yet.

import { CorbadoAuth } from '@corbado/react';

const AuthPage = () => {
  const onLoggedIn = () => {
    // Navigate or perform actions after successful login
  };

  return <CorbadoAuth onLoggedIn={onLoggedIn} />;
};

export default AuthPage;

PasskeyList component

Users that are logged in want to see a list of all their existing passkeys and they want to manage them. You can make this possible by using the PasskeyList component. It shows all passkeys of the currently logged in user and allows them to add and remove passkeys.

import { PasskeyList } from '@corbado/react';

const PasskeysView = () => {
  // Additional logic or styling

  return (
    <div>
      <PasskeyList />
    </div>
  );
};

export default PasskeysView;

Accessing Authentication State

If you want to know if the user is currently authenticated or not make use of the useCorbado hook. Use isAuthenticated and loading to check the authentication state.

import { useCorbado } from '@corbado/react';

const HomePage = () => {
  const { loading, isAuthenticated } = useCorbado();

  if (loading) {
    // Render loading state
  }

  if (isAuthenticated) {
    // Render authenticated state
  }

  // Additional implementation
};

export default HomePage;

If you need more information about the user (e.g. name, email, etc.) use the useCorbadoSession hook. It also gives you access to the user's shortSession which you can use to make authenticated requests to your backend.

import { useCorbadoSession } from '@corbado/react';

const HomePage = () => {
  const { loading, user } = useCorbadoSession();

  if (loading) {
    // Render loading state
  }

  if (user) {
    // Render authenticated state
  }
};

export default HomePage;

Remember to check loading state of the hook before using authentication states.

Logging Out

Implement logout functionality easily with the logout method from the useCorbado hook:

import { useCorbado } from '@corbado/react';

const LogoutButton = () => {
  const { logout } = useCorbado();

  const handleLogout = () => {
    logout();
    // Redirect or perform additional actions after logout
  };

  // UI logic and styling for logout button
};

export default LogoutButton;

💡 Example Application


📄 Documentation & Support

For support and questions please visit our Slack channel. For more detailed information and advanced configuration options, please visit our Documentation Page.

🚢 Release Notes

Find out what we've shipped! Check out the changelog files here


🔒 License

This project is licensed under the MIT License - see the LICENSE file for details.

2.7.0

3 days ago

2.7.0-alpha.0

4 days ago

2.6.2-alpha.0

5 days ago

2.6.1-alpha.0

5 days ago

2.6.0

9 days ago

2.6.0-alpha.0

17 days ago

2.5.4

19 days ago

2.5.3-alpha.0

21 days ago

2.5.5-alpha.0

20 days ago

2.5.4-alpha.0

21 days ago

2.5.2-alpha.0

21 days ago

2.5.1-alpha.0

23 days ago

2.5.0-alpha.0

25 days ago

2.4.2-alpha.0

26 days ago

2.4.1-alpha.0

1 month ago

2.4.0-alpha.0

1 month ago

2.3.0-alpha.0

1 month ago

2.2.1-alpha.0

1 month ago

2.2.2-alpha.0

1 month ago

2.2.0-alpha.0

1 month ago

2.0.4-alpha.0

1 month ago

2.1.2-alpha.0

1 month ago

2.1.1-alpha.0

1 month ago

2.1.0-alpha.0

1 month ago

2.0.3-alpha.0

1 month ago

2.0.2-alpha.0

2 months ago

2.0.1-alpha.0

2 months ago

2.0.0-alpha.0

2 months ago

1.1.14

2 months ago

1.1.13

2 months ago

1.1.12

2 months ago

1.1.11

2 months ago

1.1.10

2 months ago

1.1.9

2 months ago

1.1.8

3 months ago

1.1.7

3 months ago

1.1.6

3 months ago

1.1.5

3 months ago

1.1.4

3 months ago

1.1.3

3 months ago

1.1.2

3 months ago

1.1.0

3 months ago

1.1.0-alpha.0

3 months ago

1.0.2

4 months ago

1.0.1

4 months ago

1.0.3

4 months ago

1.0.0

4 months ago

0.1.1-alpha.6

4 months ago

0.1.1-alpha.8

4 months ago

0.1.1-alpha.7

4 months ago

0.1.1-alpha.4

4 months ago

0.1.1-alpha.3

4 months ago

0.1.1-alpha.2

4 months ago

0.1.1-alpha.1

5 months ago

0.1.1-alpha.0

5 months ago