skyrpex / laravel-nuxt-js

Build a SPA with Laravel and Nuxt.
https://www.npmjs.com/package/laravel-nuxt
MIT License
146 stars 20 forks source link

More docs explaining the relationship between Nuxt and Laravel #1

Closed lmj0011 closed 5 years ago

lmj0011 commented 6 years ago

I stumbled here, looking for projects that try to combine Nuxt.js and Laravel. Yours seems to be the most lightweight so far, especially when compared to https://github.com/cretueusebiu/laravel-nuxt

I have a few questions before giving this project a shot:

How does authentication get handled in the SPA?

How does the Laravel Controllers pass data to the nuxt pages, via API call?

Can the full Nuxt directory structure be used?

I understand this project is very new, however some documentation on how the Nuxt spa communicates with Laravel and what restrictions there may be would be helpful.

skyrpex commented 6 years ago

Hi there! You're right, the docs could be improved a bit.

How does authentication get handled in the SPA?

The best strategy is to rely on cookies to handle the authentication. Laravel's default web guard works transparently to you, but if you're going to implement API methods, you should take a look at Laravel Passport.

Passport's api guard (with the CreateFreshApiToken middleware) will use another cookie to handle the authentication. You can read more here.

Again, cookies should seamlessly work between your Nuxt SPA and the Laravel backend. That's because Laravel is actually serving the Nuxt assets, even in development mode.

How does the Laravel Controllers pass data to the nuxt pages, via API call?

Yes.

IMO, your very first API call should always be to something like /api/me and return your user's name, email, etc. If the API call returns a 401/403, this means that the user is not authenticated. Therefore, you should redirect the SPA to your login page. You can use a Nuxt middleware for that API call.

Do you think I should make a small tutorial on getting started with basic authentication, along with a login page and a Nuxt middleware?

Can the full Nuxt directory structure be used?

Yes, just that the Nuxt base directory is under resources/nuxt.

I understand this project is very new, however some documentation on how the Nuxt spa communicates with Laravel and what restrictions there may be would be helpful.

This project needs a tutorial, indeed. Thanks for your interest in this project!

lmj0011 commented 6 years ago

Do you think I should make a small tutorial on getting started with basic authentication, along with a login page and a Nuxt middleware?

Yes, that would be great.

skyrpex commented 6 years ago

I still remember this, it's just I'm not spending much time into code these days :+1:

paolog22 commented 6 years ago

documentation please :) thank you.

skyrpex commented 5 years ago

Here you have: https://dev.to/skyrpex/laravelnuxt-under-the-hood-36lp