#Ionic Auth starter with Laravel Passport
Run command
composer install
cp .env.example .env
php artisan key:generate
Configure your database in .env file
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your-database-name
DB_USERNAME=homestead
DB_PASSWORD=secret
Run migrations
php artisan migrate
Install passport
php artisan passport:install
Install node modules
npm install
Copy client credentials of passport from table oauth_clients usually is the second record
Client id 2 named Laravel Password Grant Client
Or create new client for ionic app and save Client ID and Client Secret
php artisan passport:client --password
Enter to file src/settings/Laravel.ts and modify json config, replace url and apiUrl with your project url and your passport client credentials
// this example is running with php artisan serve
export const Service: any = {
url: 'http://127.0.0.1:800',
apiUrl: 'http://127.0.0.1:800/api',
passport: {
'grant_type': 'password',
'client_id': 'your-client-id',
'client_secret': 'your-client-secret',
}
};
Import AuthProvider to your page
Example
import { AuthProvider } from '../../providers/auth/auth';
And add this function
async ionViewCanEnter () {
let isAuthenticated = await this.authService.checkIsAuthenticated();
return isAuthenticated;
}