Home Web Front-end JS Tutorial The interceptor determines the operation after the token fails and jumps.

The interceptor determines the operation after the token fails and jumps.

Apr 16, 2018 pm 02:02 PM
token Invalid

This time I will bring you the operation after the interceptor determines the token invalid jump. What are the precautions after the interceptor determines the token invalid jump. The following is a practical case, let's take a look.

Set global token judgment in the interceptor, which means that the token will be verified for every http request, and the token expiration return code agreed with the background can customize the jump path;

var token = window.localStorage.getItem("token");
Vue.http.interceptors.push(function(request, next) {
  request.headers.set('token', token); //setting request.headers
  next(function(response){
    if(response.body.code===401){ //与后台约定登录失效的返回码
      parent.location.href ='/login.html';
    }
    return response
  })
})
Copy after login

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Detailed explanation of the steps for setting header information in the vue-resource interceptor

js css perfect web page loading User experience at the time

The above is the detailed content of The interceptor determines the operation after the token fails and jumps.. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What to do if the login token is invalid What to do if the login token is invalid Sep 14, 2023 am 11:33 AM

Solutions to invalid login token include checking whether the Token has expired, checking whether the Token is correct, checking whether the Token has been tampered with, checking whether the Token matches the user, clearing the cache or cookies, checking the network connection and server status, logging in again or requesting a new Token. Contact technical support or developers, etc. Detailed introduction: 1. Check whether the Token has expired. The login Token usually has a validity period set. Once the validity period exceeds, it will be considered invalid, etc.

How to solve the problem of invalid login token How to solve the problem of invalid login token Sep 14, 2023 am 10:57 AM

The problem of invalid login token can be solved by checking the network connection, checking the token validity period, clearing cache and cookies, checking login status, contacting the application developer and strengthening account security. Detailed introduction: 1. Check the network connection, reconnect to the network or change the network environment; 2. Check the token validity period, obtain a new token, or contact the developer of the application; 3. Clear cache and cookies, clear browser cache and Cookie, and then log in to the application again; 4. Check the login status.

How to solve the common problem of Laravel login time invalidation How to solve the common problem of Laravel login time invalidation Mar 06, 2024 pm 09:24 PM

How to solve the common problem of Laravel login time expiration When using Laravel to develop web applications, login authentication is a very important function. However, sometimes if a user does not operate for a long time after logging in, the page may automatically log out or the authentication may fail. This problem is relatively common. The following will introduce how to solve this problem by setting the session time and provide specific code examples. 1. Set the session expiration time in Laravel, by default sessi

How to solve the problem of storing user tokens in Redis How to solve the problem of storing user tokens in Redis May 31, 2023 am 08:06 AM

Redis stores user tokens. When designing a system similar to e-commerce, a common requirement is that each page needs to carry logged-in user information. There are two common solutions: using cookies to save and using JWT to save. But if Redis cache is used in the system, there is also a third solution - caching the user token in Redis. Generate a token when logging in and store it in Redis //Generate a token object and save it in redis redisTemplate.opsForHash().put("token","user",user)

How Vue3+Vite uses dual tokens to achieve senseless refresh How Vue3+Vite uses dual tokens to achieve senseless refresh May 10, 2023 pm 01:10 PM

1. Token login authentication jwt: JSONWebToken. It is an authentication protocol that is generally used to verify the requested identity information and identity permissions. Composed of three parts: Header, Hayload, Signatureheader: that is, the header information, which is the basic information describing this token, json format {"alg":"HS256", //indicates the signature algorithm, the default is HMACSHA256 (written as HS256) "type":"JWT"//Indicates the type of Token. JWT tokens are uniformly written as JWT}pa

PHP and REDIS: How to implement distributed cache invalidation and update PHP and REDIS: How to implement distributed cache invalidation and update Jul 21, 2023 pm 05:33 PM

PHP and REDIS: How to implement distributed cache invalidation and update Introduction: In modern distributed systems, cache is a very important component, which can significantly improve the performance and scalability of the system. At the same time, cache invalidation and update is also a very important issue, because if the invalidation and update of cache data cannot be handled correctly, it will lead to system data inconsistency. This article will introduce how to use PHP and REDIS to implement distributed cache invalidation and update, and provide relevant code examples. 1. What is RED

How to solve C++ syntax error: 'expected primary-expression before ':' token'? How to solve C++ syntax error: 'expected primary-expression before ':' token'? Aug 26, 2023 pm 04:06 PM

How to solve C++ syntax error: 'expectedprimary-expressionbefore':'token'? Syntax errors are a common problem in C++ programming. One of the common errors is the "expectedprimary-expressionbefore':'token" error message. This error usually occurs when using conditional expressions and the ternary operator. This article will introduce the cause of this error

Andrew Ng's ChatGPT class went viral: AI gave up writing words backwards, but understood the whole world Andrew Ng's ChatGPT class went viral: AI gave up writing words backwards, but understood the whole world Jun 03, 2023 pm 09:27 PM

Unexpectedly, ChatGPT would still make stupid mistakes to this day? Master Ng Enda pointed it out at the latest class: ChatGPT will not reverse words! For example, let it reverse the word lollipop, and the output is pilollol, which is completely confusing. Oh, this is indeed a bit surprising. So much so that after a netizen who listened to the class posted a post on Reddit, it immediately attracted a large number of onlookers, and the post quickly reached 6k views. And this is not an accidental bug. Netizens found that ChatGPT is indeed unable to complete this task, and the results of our personal testing are also the same. △The actual test of ChatGPT (GPT-3.5) and even many products including Bard, Bing, Wen Xinyiyan, etc. does not work. △Actual test Bard△Actual test Wenxinyiyan

See all articles