Courses

[NEW] React Native Mobile App with Laravel 12 API

Handling Sanctum Session Tokens

You're reading a FREE PREVIEW of a PREMIUM course.
Summary of this lesson:
- Restore Laravel's authentication middleware to properly secure API endpoints
- Implement secure token storage using expo-secure-store to safely persist authentication tokens
- Create auth service methods for retrieving, saving, and clearing session tokens
- Add Axios interceptors to automatically include authentication tokens in API requests
- Handle 401 Unauthorized responses by clearing the session and redirecting to login

Link to the repository

[Only for premium members]

Our users can finally log in, and we are saving their API token. So, let's start using it to make our API calls:

  • Restore the Laravel code changes to the original state.
  • Implement expo-secure-store to store the token in the device's secure storage.
  • Write Axios interceptors to add the token to the headers of all requests.

Reverting Laravel Code Changes

Let's start this by reverting all of our Laravel code changes to the original state:

app/Http/Controllers/Api/CategoryController.php

public function store(StoreCategoryRequest $request)
{
$category = Category::create($request->validated());
$category = auth()->user()->categories()->create($request->validated());
 
return new CategoryResource($category);
}

And then...

The full lesson is only for Premium Members.
Want to access all 19 text lessons of this course? (91 min read)

You also get:

  • 77 courses
  • Premium tutorials
  • Access to repositories
  • Private Discord