Project list

Open source · React Native

React Native Sanctum

Use Laravel Sanctum in a React Native app. A library for signing in, signing out and accessing the current user.

React NativeLaravel Sanctum

Authentication with Laravel Sanctum

This package connects a Laravel Sanctum backend to a React Native app. It provides functions for signing in, signing out, accessing the current user and checking authentication state.

Using it in an app

An AuthProvider wraps the application. Components access authentication functions and user state through useAuth.

import { AuthProvider, useAuth } from 'react-native-laravel-sanctum';

API endpoints are configured in the provider. The backend needs to provide the corresponding sign-in, sign-out and user endpoints.

Installation

npm install react-native-laravel-sanctum

The package uses expo-secure-store and therefore requires a new native app build. The README includes setup instructions and an example app.

In the source code

Technical structure

Explore each part directly in the repository.

  1. App state

    AuthProvider holds the user and authentication state. Components access them through useAuth.

    View source code
  2. Requests to Laravel

    AuthService calls the configured endpoints and sets the stored token in the Authorization header.

    View source code
  3. Token on the device

    The native TokenStorage implementation stores, reads and removes the token through Expo SecureStore.

    View source code

Next project

Margarita Hanke

Client project · Art & content

Back to homeAll projects