cretueusebiu / laravel-nuxt

A Laravel-Nuxt starter kit.
https://laravel-nuxt.cretueusebiu.com
MIT License
1.15k stars 262 forks source link

SSR and MustVerifyEmail issue #137

Open rudolfbruder opened 3 years ago

rudolfbruder commented 3 years ago

Hi there,

First of all thanks for this great boilerplate. I am using it a lot. I found an issue when if you want to use SSR out of box without building the SPA version of your project your api path is inaccessible and it is throwing the file_get_contents error. This for me is not an issue because the api on subdomain works and if you provide a token you can use all the api endpoints where authorization is required.

However problem out of box is that the links in the notification which is send to user once they are registered (if MustVerify is enabled) contains link to the API back end end point.

There is a file called VerifyEmail.php and i modified the code a bit so that the link is actually sending end users to the front-end. ENV variables and config file needs to be setup.

    protected function verificationUrl($notifiable)
    {
        $url = URL::temporarySignedRoute(
            'verification.verify',
            Carbon::now()->addMinutes(60),
            ['user' => $notifiable->id]
        );

        info($url);
        return str_replace(config('app.api_url'), config('app.client_url'), $url);
        // return str_replace('/api', '', $url);
    }

My .env variables: APP_URL=http://localhost:3000 API_URL=http://localhost:800

My app.php file config for this includes these lines

'url' => env('APP_URL', 'http://localhost:3000'), 'api_url' => env('API_URL', 'http://localhost'),

Also i found out that these lines in file EventServiceProvider.php

protected $listen = [ Registered::class => [ SendEmailVerificationNotification::class, ], ];

Are causing duplicate verification email generation because this email generation is also called in RegisterController.php file

    protected function registered(Request $request, User $user)
    {
        if ($user instanceof MustVerifyEmail) {
            $user->sendEmailVerificationNotification();

            return response()->json(['status' => trans('verification.sent')]);
        }
        return response()->json($user);
    }

What do you think about it?