Authentication with Laravel and Vue.js

After successfully implementing Laravel-Vue.js Authentication using Passport API, I am now able to obtain the token and send requests to api/user. Initially, I used the normal authentication process by sending data through a POST request to /login, which resulted in me being authenticated and receiving a $_SESSION.

However, upon completing the implementation of the Passport API, I realized that my session no longer starts when attempting to authenticate. I even tried changing the middleware to api, but that didn't work either. This led me to two main questions:

  • Do I still need to rely on sessions or will the access_token handle communication with the backend?
  • Is it normal for the session to not start after implementing API Auth? While I do get tokens and user details upon authentication, there is no session in the backend.

Answer №1

When building your backend to support an API (REST Service) for your client-side application, sessions may not be necessary.

If all of your routes fall under the API AUTH middleware, you can use access tokens to retrieve data from backend services without requiring sessions.

However, if your routes (used to provide data to the client app) are protected by web and auth middleware, sessions become essential in order to access these routes and retrieve data.

In simple terms, whether or not you need sessions depends on your routes and overall architecture. Developing a Single Page Application (SPA) or a JavaScript-powered application would typically require all routes to be placed under the API and API AUTH, which Passport conveniently offers out of the box.

In conclusion, if your routes are protected with
'middleware' => 'auth:api'
access tokens will suffice for accessing those routes and retrieving data, eliminating the need for sessions.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for capturing a jQuery trigger in traditional JavaScript

I am trying to trigger an event using jQuery and I want to bind to it in a non-jQuery script. It appears that while I can bind to the event in jQuery using on, I am unable to do so with addEventListener. Check out this jsFiddle for a demonstration: http: ...

Changing the input programmatically does not trigger an update in the Angular model

I am currently facing a challenge where I have a text input that is connected to a model value in my application. However, I am struggling to programmatically change the input value and ensure that this change reflects in the model. My understanding is th ...

The operation to set a nickname in Discord.js was unsuccessful due to insufficient permissions

Recently, I started using discord.js to create a simple bot. Whenever I try to change the nickname by calling message.member.setNickname("Another Nickname").then(console.log, console.log); I receive the following error message: { name: ' ...

"The server responded with a 405 error message indicating that the requested method

I have been working on a registration form project using HTML, JS, NodeJS, and SQLite. However, I am encountering an issue with the fetch function when trying to post the inputted information into the database. I keep receiving a POST 405 (Method Not Allo ...

Sketchup's Vue.js integration allows for a seamless and intuitive interface

One interesting aspect of Sketchup is that it uses HTML for its extension user interface. Currently, I am working on creating an interface with Vue.js + Vuetify for Sketchup. While Sketchup can render the page successfully, I am facing difficulties in send ...

Vue's drag-and-drop functionality is effective for dragging entire groups, but it does not work

Below is the code that enables dragging of groups in toListFetchRouteA1: <draggable id="first" data-source="juju" :list="toListFetchRouteA1" class="list-group" draggable=".item" group="a"> <div class="list-group-item item" v-for="teamfetch in ...

Storing arrays of objects in Laravel involves creating models, defining relationships between them,

I am in a situation where I have a form set up with specific input fields for shipping rules. The form structure is as follows: <shipping-rules-form> <div class="row" v-for="(input,index) in form.inputs" :key="index&qu ...

Using AJAX to dynamically update content via HTTP requests

Why do I keep seeing "loading..." instead of the content from data.php? xmlhttp = new XMLHttpRequest(); function fetchData () { xmlhttp.onreadystatechange = function () { if(xmlhttp.readyState = 4 && xmlhttp.status == 20 ...

Determining the duration since generating a unique objectid in mongodb

I am currently developing an application that offers users the option to reset their passwords. The process is quite straightforward - after entering his email address, the user will receive a link containing the new objectid number. For example: /reset- ...

Utilize Vue's "v-if" directive to dynamically display or conceal steps according to the

Currently, both steps are hidden even though the step is 1. I must be doing something wrong here. When the step is one, it should display the form and when the step is 2, it should show the error message "Property or method 'step' is not defined ...

Implementing a validator based on the operator selection in react-querybuilder

Is it possible to add validators to fields that are only active when using the like operator? For example, if the like or unlike operators are used in the phoneNumber field without the % sign, it should be invalid. If the = operator is used, the % sign sho ...

The AngularJS script is throwing an error that states "ReferenceError: Invalid left-hand side in assignment

While attempting to establish a connection with a webservice, I made an attempt using AngularJS $http option. However, when testing it out, I encountered an error in the console of my Chrome browser: ReferenceError Invalid left-hand side in assignment. Des ...

Having trouble constructing the Grand-Stack-Starter api because babel-node is not being recognized

As I endeavor to create the initial api for the Grand Stack Starter, I encounter difficulties every time I try to execute npm start: >nodemon --exec babel-node src/index.js [nodemon] 1.18.7 [nodemon] to restart at any time, enter `rs` [nodemon] watchi ...

A guide to querying JSON data in a backend database with JavaScript

My backend JSON DB is hosted on http://localhost:3000/user and contains the following data: db.json { "user": [ { "id": 1, "name": "Stephen", "profile": "[Unsplash URL Placehol ...

Create a PHP form that includes text and image inputs with the help of AdminLTE and integrates DropZone.js

I have been working with a template from adminLTE and you can check it out at the following link: . At this point, I am trying to upload images first and then use the image names as input text elements in my main form for submission. However, I have encou ...

Array containing two objects in a two-dimensional format

In the example provided, I am working with a 2D array. Link to the example: https://codesandbox.io/s/v0019po127 I am noticing different results depending on whether I use the browser console or Codesandbox's console. I have attempted using JSON.str ...

deleting a aircraft upon the addition of another in three.js

I am striving to implement a button that toggles between different terrain-generating functions and removes the previous terrain. The current issue I am facing is that the planes stack on top of each other. You can see an image of the problem here. There ...

What is the solution to the error message that states a bind message provides 4 parameters, while a prepared statement "" necessitates 5?

Is there a way to fix the issue where the bind message provides 4 parameters but the prepared statement "" requires 5? I've tried solutions from others who faced similar problems without success. (I've included all classes for better error unders ...

Attempting to streamline this particular JavaScript function

I have been struggling with a function that I believe could be written more effectively. My goal is to simplify it while still maintaining its functionality. function changeLetters(text) { text = text.toLowerCase(); for (var i = 0; i < text.length; ...

initiating a submission upon the occurrence of an onchange event on an input field of type "file"

I have encountered an issue while trying to submit a form using the onchange event of an input element with type file. The problem is that it submits an empty form even when a file has been chosen. Here is the code snippet: var form = document.createElem ...