Skip to content

Commit 1ef51bc

Browse files
committed
Merge branch 'next'
2 parents 9c45056 + 693ef7f commit 1ef51bc

File tree

91 files changed

+13369
-9572
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+13369
-9572
lines changed

.env.example

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
APP_NAME=LaravelNuxt
1+
APP_NAME="Laravel Nuxt"
22
APP_ENV=local
33
APP_KEY=
44
APP_DEBUG=true
5-
APP_LOG_LEVEL=debug
5+
APP_URL=http://localhost
66

7-
APP_URL=http://api.laravel-nuxt.test
8-
CLIENT_URL=http://localhost:3000
7+
LOG_CHANNEL=stack
98

109
DB_CONNECTION=mysql
1110
DB_HOST=127.0.0.1
1211
DB_PORT=3306
13-
DB_DATABASE=homestead
14-
DB_USERNAME=homestead
15-
DB_PASSWORD=secret
12+
DB_DATABASE=laravel
13+
DB_USERNAME=root
14+
DB_PASSWORD=
1615

1716
BROADCAST_DRIVER=log
1817
CACHE_DRIVER=file
18+
QUEUE_CONNECTION=sync
1919
SESSION_DRIVER=file
20-
QUEUE_DRIVER=sync
20+
SESSION_LIFETIME=120
2121

2222
REDIS_HOST=127.0.0.1
2323
REDIS_PASSWORD=null
@@ -30,8 +30,14 @@ MAIL_USERNAME=null
3030
MAIL_PASSWORD=null
3131
MAIL_ENCRYPTION=null
3232

33+
AWS_ACCESS_KEY_ID=
34+
AWS_SECRET_ACCESS_KEY=
35+
AWS_DEFAULT_REGION=us-east-1
36+
AWS_BUCKET=
37+
3338
PUSHER_APP_ID=
3439
PUSHER_APP_KEY=
3540
PUSHER_APP_SECRET=
41+
PUSHER_APP_CLUSTER=mt1
3642

3743
JWT_TTL=1440

.eslintrc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
"root": true,
33
"parserOptions": {
44
"parser": "babel-eslint",
5-
"ecmaVersion": 2017,
65
"sourceType": "module"
76
},
87
"extends": [
9-
"plugin:vue/recommended",
10-
"@vue/standard"
8+
"@nuxtjs"
119
],
1210
"rules": {
1311
"vue/max-attributes-per-line": "off"

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
/public/storage
44
/storage/*.key
55
/vendor
6-
/.idea
7-
/.vagrant
6+
.env
7+
.env.backup
8+
.phpunit.result.cache
89
Homestead.json
910
Homestead.yaml
1011
npm-debug.log
1112
yarn-error.log
12-
.env
1313
.nuxt
1414
/dist
1515
/public/_nuxt
16+
*.code-workspace

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ language: php
33
php:
44
- 7.1
55
- 7.2
6+
- 7.3
67

78
install:
89
- travis_retry composer install --no-interaction --prefer-dist --no-suggest

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog
22

3+
## 2.0.0 - 2019-07-26
4+
5+
- Upgrade to Nuxt 2.8
6+
- Upgrade to Laravel 5.8
7+
- Added email verification
8+
- SPA mode by default
9+
- Update npm dependencies
10+
- Removed yarn.lock in favor of package-lock.json
11+
312
## 1.1.0 - 2018-05-10
413

514
- Upgrade to Laravel 5.6

README.md

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,20 @@
1212

1313
## Features
1414

15-
- Laravel 5.6
16-
- Nuxt 1.4
17-
- VueI18n
18-
- SSR or SPA
19-
- Authentication with JWT
15+
- Nuxt 2.8
16+
- Laravel 5.8
17+
- SPA or SSR
2018
- Socialite integration
21-
- Bootstrap 4 + Font Awesome 5
22-
- Login, register, password reset and profile pages
19+
- VueI18n + ESlint + Bootstrap 4 + Font Awesome 5
20+
- Login, register, email verification and password reset
2321

2422
## Installation
2523

2624
- `composer create-project --prefer-dist cretueusebiu/laravel-nuxt`
2725
- Edit `.env` to set your database connection details and `APP_URL` (the url to your Laravel application)
2826
- (When installed via git clone or download, run `php artisan key:generate` and `php artisan jwt:secret`)
2927
- `php artisan migrate`
30-
- `yarn` / `npm install`
28+
- `npm install`
3129

3230
## Usage
3331

@@ -37,21 +35,30 @@
3735
npm run dev
3836
```
3937

40-
### Production with SSR
38+
You can access your application at `http://localhost:3000`.
39+
40+
### Production
4141

4242
```bash
4343
npm run build
44-
npm run start
4544
```
4645

46+
You can access your application the url you set `APP_URL` to.
47+
48+
### Enable SSR
49+
50+
- Remove `mode: 'spa'` and `'~plugins/nuxt-client-init'` from `client/nuxt.config.js`
51+
- Edit `.env` to set `APP_URL=http://api.example.com` and `CLIENT_URL=http://example.com`
52+
- Run `npm run build` and `npm run start`
53+
4754
#### Nginx Proxy
4855

4956
For Nginx you can add a proxy using the follwing location block:
5057

5158
```
5259
server {
5360
location / {
54-
proxy_pass http://HOST:PORT;
61+
proxy_pass http://http://127.0.0.1:3000;
5562
proxy_http_version 1.1;
5663
proxy_set_header Upgrade $http_upgrade;
5764
proxy_set_header Connection 'upgrade';
@@ -61,8 +68,6 @@ server {
6168
}
6269
```
6370

64-
Where `HOST` is the ip address of your server and `PORT` is the port you're running the application (3000 by default).
65-
6671
#### Process Manager
6772

6873
In production you need a process manager to keep the Node server alive forever:
@@ -90,15 +95,6 @@ After each deploy you'll need to restart the process:
9095
pm2 restart laravel-nuxt
9196
```
9297

93-
### Production without SSR
94-
95-
If you don't want server side rendering you can use the [mode](https://nuxtjs.org/api/configuration-mode#the-mode-property) option:
96-
97-
- Uncomment `mode: 'spa'` and `'~plugins/nuxt-client-init'` in `client/nuxt.config.js`
98-
- Uncomment `// ->prefix('api')` in `app/Providers/RouteServiceProvider.php`
99-
- Set `APP_URL=http://example.com/api` and `CLIENT_URL=http://example.com` in your `.env`
100-
- Run `npm run build`
101-
10298
Make sure to read the [Nuxt docs](https://nuxtjs.org/).
10399

104100
## Notes

app/Exceptions/Handler.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Exceptions;
44

55
use Exception;
6+
use Illuminate\Auth\AuthenticationException;
67
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
78

89
class Handler extends ExceptionHandler
@@ -50,4 +51,18 @@ public function render($request, Exception $exception)
5051
{
5152
return parent::render($request, $exception);
5253
}
54+
55+
/**
56+
* Convert an authentication exception into a response.
57+
*
58+
* @param \Illuminate\Http\Request $request
59+
* @param \Illuminate\Auth\AuthenticationException $exception
60+
* @return \Illuminate\Http\Response
61+
*/
62+
protected function unauthenticated($request, AuthenticationException $exception)
63+
{
64+
return $request->expectsJson()
65+
? response()->json(['message' => $exception->getMessage()], 401)
66+
: redirect()->guest(url('/login'));
67+
}
5368
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace App\Exceptions;
4+
5+
use Illuminate\Validation\ValidationException;
6+
7+
class VerifyEmailException extends ValidationException
8+
{
9+
/**
10+
* @param \App\User $user
11+
* @return static
12+
*/
13+
public static function forUser($user)
14+
{
15+
return static::withMessages([
16+
'email' => [__('You must :linkOpen verify :linkClose your email first.', [
17+
'linkOpen' => '<a href="/email/resend?email='.urlencode($user->email).'">',
18+
'linkClose' => '</a>',
19+
])],
20+
]);
21+
}
22+
}

app/Http/Controllers/Auth/ForgotPasswordController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ public function __construct()
2323
/**
2424
* Get the response for a successful password reset link.
2525
*
26+
* @param \Illuminate\Http\Request $request
2627
* @param string $response
2728
* @return \Illuminate\Http\RedirectResponse
2829
*/
29-
protected function sendResetLinkResponse($response)
30+
protected function sendResetLinkResponse(Request $request, $response)
3031
{
3132
return ['status' => trans($response)];
3233
}

app/Http/Controllers/Auth/LoginController.php

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use Illuminate\Http\Request;
66
use App\Http\Controllers\Controller;
7+
use App\Exceptions\VerifyEmailException;
8+
use Illuminate\Contracts\Auth\MustVerifyEmail;
9+
use Illuminate\Validation\ValidationException;
710
use Illuminate\Foundation\Auth\AuthenticatesUsers;
811

912
class LoginController extends Controller
@@ -30,20 +33,25 @@ protected function attemptLogin(Request $request)
3033
{
3134
$token = $this->guard()->attempt($this->credentials($request));
3235

33-
if ($token) {
34-
$this->guard()->setToken($token);
36+
if (! $token) {
37+
return false;
38+
}
3539

36-
return true;
40+
$user = $this->guard()->user();
41+
if ($user instanceof MustVerifyEmail && ! $user->hasVerifiedEmail()) {
42+
return false;
3743
}
3844

39-
return false;
45+
$this->guard()->setToken($token);
46+
47+
return true;
4048
}
4149

4250
/**
4351
* Send the response after the user was authenticated.
4452
*
4553
* @param \Illuminate\Http\Request $request
46-
* @return \Illuminate\Http\Response
54+
* @return \Illuminate\Http\JsonResponse
4755
*/
4856
protected function sendLoginResponse(Request $request)
4957
{
@@ -52,11 +60,31 @@ protected function sendLoginResponse(Request $request)
5260
$token = (string) $this->guard()->getToken();
5361
$expiration = $this->guard()->getPayload()->get('exp');
5462

55-
return [
63+
return response()->json([
5664
'token' => $token,
5765
'token_type' => 'bearer',
5866
'expires_in' => $expiration - time(),
59-
];
67+
]);
68+
}
69+
70+
/**
71+
* Get the failed login response instance.
72+
*
73+
* @param \Illuminate\Http\Request $request
74+
* @return \Illuminate\Http\JsonResponse
75+
*
76+
* @throws \Illuminate\Validation\ValidationException
77+
*/
78+
protected function sendFailedLoginResponse(Request $request)
79+
{
80+
$user = $this->guard()->user();
81+
if ($user instanceof MustVerifyEmail && ! $user->hasVerifiedEmail()) {
82+
throw VerifyEmailException::forUser($user);
83+
}
84+
85+
throw ValidationException::withMessages([
86+
$this->username() => [trans('auth.failed')],
87+
]);
6088
}
6189

6290
/**

0 commit comments

Comments
 (0)