Courses

[NEW] NativePHP: Build Mobile App with Laravel

Login/Register Screens and Calling API

You're reading a FREE PREVIEW of a PREMIUM course.

Link to the repository

[Only for premium members]

Let's start implementing features into our Application:

  • Setting up API URL
  • Setting up custom middleware to check users' Auth status
  • Registration via API
  • Login via API

By the end, we should have a working Login/Registration system.


Setting Up API URL

First thing we need to do is add our API URL to our .env file:

.env.

# ...
 
API_URL=http://nativephp-events-app-api.test/api

Of course, we should never load the .env file in our code, so let's set up a config file for this:

config/services.php

// ...
 
'slack' => [
'notifications' => [
'bot_user_oauth_token' => env('SLACK_BOT_USER_OAUTH_TOKEN'),
'channel' => env('SLACK_BOT_USER_DEFAULT_CHANNEL'),
],
],
 
'api' => [
'url' => env('API_URL'),
],
 
];

Now, we will be able to get our API URL by calling:

config('services.api.url')

Creating Custom Middleware

Now we have to think about our sessions. The typical auth middleware won't work here, as we are authenticated via token. So let's create a new one:

php artisan make:middleware ApiTokenExists

And inside it, we'll add:

  • A check to see if we have token set in our session
  • An API call to load the user Profile

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

You also get:

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