GithubHelp home page GithubHelp logo

Comments (4)

GautierDele avatar GautierDele commented on August 17, 2024

What's wrong with cookies ? I can confirm having a "PHP_SESS_ID" cookie that should do the job. Other cookies should be accessible from front side.

I don't really know what was meant by @mentAl-maZe when he was saying that you can share the session state. You might be able to access the session while requesting laravel since your cookies have the "PHP_SESS_ID" available.

Be aware that this is not working if you are working with a PWA.

from nuxt-laravel.

gitllermopalafox avatar gitllermopalafox commented on August 17, 2024

Hi @GautierDele thanks for your answer.

I've been trying to get it working without success...

I try to login with the laravel default auth and then get user status (if the user is logged in or not) but I always get false.

The short version: it seems axios is not sending back the cookies to the back.

The long version:

This is part of my code in the front:

User login:

this.$axios
      .$post('/login', { email: '[email protected]', password: '123456' })
      .then(console.log)

Check user status:

this.$axios.$post('/loggedin', {}).then(console.log)

nuxt.config.js -> Axios module configuration

...
  axios: {
    baseURL: "http://localhost:3000", // .custom-domain.test,
    credentials: true
  },

In the backend:

My routes file (web.php) I use the web guard:

Route::get('/', function () {
    return view('welcome');
});

Route::namespace('Api') // <--- Just for better controllers structure /app/Http/Controllers/Api
    ->group(function () {
        Route::post('/signup', 'Auth\RegisterController@register');
        Route::post('/login', 'Auth\LoginController@login');
        Route::post('/loggedin', 'Auth\LoginController@isLoggedIn');
    });

Route::get('/app{path}', '\\' . Pallares\LaravelNuxt\Controllers\NuxtController::class)->name('nuxt')->where('path', '.*');

In my LoginController the only difference with original one is the type of response, I return a json instead of redirect...

...
    protected function sendLoginResponse(Request $request)
    {
        $request->session()->regenerate();

        $this->clearLoginAttempts($request);

        return $this->authenticated($request, $this->guard()->user());
    }

    protected function authenticated(Request $request, $user)
    {
        return response()->json($user);
    }
...

In the session.php file I have tried with different settings like:

...
'domain' => '.localhost',  //.custom-domain.test,
'http_only' => false | true,
'same_site' => 'lax',
...
etc...

Can you help me with some advices of how you got it work?

Thanks in advance.

from nuxt-laravel.

gitllermopalafox avatar gitllermopalafox commented on August 17, 2024

Hi again, after trying several settings, I got it working with... in the session.php file the "domain" option set to ".my-custom-domain.test" nothing else. I couldn't get it to work only with localhost.

from nuxt-laravel.

mentAl-maZe avatar mentAl-maZe commented on August 17, 2024

@gitllermopalafox
Sry for the long silence, i've been crazy busy and didn't find any time for foss stuff...

@GautierDele Thanks for pitching in ๐Ÿ‘

I'm happy your problem is resolved, but could you maybe provide a repo to reproduce your original issue, so i can investigate (once i have time...)

from nuxt-laravel.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.