Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JWT token 解析错误 #8360

Closed
kala888 opened this issue Dec 24, 2020 · 10 comments · Fixed by #9545 or #9555
Closed

JWT token 解析错误 #8360

kala888 opened this issue Dec 24, 2020 · 10 comments · Fixed by #9545 or #9555
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Milestone

Comments

@kala888
Copy link
Contributor

kala888 commented Dec 24, 2020

相关平台

微信小程序

复现仓库

https://github.com/kala888/nice-router-taro
小程序基础库: 2.14.0
使用框架: React

复现步骤

taro 3.0.21 出现此问题,版本降到 3.0.16不会出现

import jwtDecode from 'jwt-decode'

const decodeToken = () => {
  console.log('xxx-11')
  const token = 'eyJraWQiOiJTVTAwMDAwOCIsInR5cCI6IkpXVCIsImFsZyI6IkhTMjU2In0.eyJ0b2tlbktleSI6ImFiY3RMOVI2M1FmYXJjMU02UnNBeCIsImVudlR5cGUiOiJkZXZfeHVudHVleGFtX3YxX2NsYXJpb25lcyIsImlzcyI6ImNsYXJpb25lcyIsImV4cCI6MTYwOTM4MzU1NCwiaWF0IjoxNjA4Nzc4NzU0LCJ1c2VyVXBsb2FkSG9tZSI6InVwbG9hZC9TZWNVc2VyL1NVMDAwMDA4IiwidGFncyI6WyJTVTAwMDAwOCJdfQ.CSPxhIcAVXOIT8wr0b3rMIDb5wlfWNOqws-pwX0Wjcs'
  jwtDecode(token)
  console.log('xxx-11222')
}

期望结果

能够支持该js 组件

实际结果

报错Illegalinvocation

环境信息

👽 Taro v3.0.21


  Taro CLI 3.0.21 environment info:
    System:
      OS: macOS 11.0.1
      Shell: 5.5.1 - /usr/local/bin/zsh
    Binaries:
      Node: 12.14.1 - ~/.nvm/versions/node/v12.14.1/bin/node
      Yarn: 1.22.5 - ~/.yarn/bin/yarn
      npm: 6.13.6 - ~/.nvm/versions/node/v12.14.1/bin/npm
    npmPackages:
      @tarojs/components: 3.0.21 => 3.0.21
      @tarojs/mini-runner: 3.0.21 => 3.0.21
      @tarojs/react: 3.0.21 => 3.0.21
      @tarojs/runtime: 3.0.21 => 3.0.21
      @tarojs/taro: 3.0.21 => 3.0.21
      @tarojs/taro-h5: 3.0.21 => 3.0.21
      @tarojs/webpack-runner: 3.0.21 => 3.0.21
      babel-preset-taro: 3.0.21 => 3.0.21
      eslint-config-taro: 3.0.21 => 3.0.21
      eslint-plugin-taro: 3.0.21 => 3.0.21
      nervjs: ^1.5.7 => 1.5.7
      react: ^16.10.0 => 16.14.0
      taro-ui: ^3.0.0-alpha => 3.0.0-alpha.3
    npmGlobalPackages:
      typescript: 3.9.5

image

@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Dec 24, 2020
@kala888
Copy link
Contributor Author

kala888 commented Dec 24, 2020

补充一下,个人怀疑和window有关,我们实际使用是,

https://github.com/kala888/nice-router-taro/blob/master/src/nice-router/auth-tools.js

有时候报错,有时候不报错,但是我issue中提供的代码,是百分百报错

@Chen-jj
Copy link
Contributor

Chen-jj commented Dec 25, 2020

目测和这个问题原因一致 #8273

在你执行 decode 前这样设置试试:

window.Date = Date
window.setTimeout = setTimeout

@kala888
Copy link
Contributor Author

kala888 commented Dec 28, 2020

@Chen-jj 设置了,不起作用。 可以下载项目https://github.com/kala888/nice-router-taro 然后点击 首页上的Login 页面,再点击登录,复现bug

image

@Chen-jj Chen-jj added this to the 3.0.22 milestone Dec 29, 2020
@Chen-jj
Copy link
Contributor

Chen-jj commented Jan 4, 2021

@kala888 3.0.17 开始,我们把小程序 global 对象上的属性都影射到 window 对象上,所以 window.atob 之前是 undefined,现在等于微信小程序的 atob。但是微信的这个 atob 函数有问题,所以就报错了。在 onLaunch 中删除 window.atob 或者赋值个 ployfill 应该就可以了。

image

@Chen-jj Chen-jj removed this from the 3.0.22 milestone Jan 4, 2021
@Chen-jj Chen-jj added the question Further information is requested label Jan 4, 2021
@kala888
Copy link
Contributor Author

kala888 commented Jan 5, 2021

@Chen-jj 直接修改jwt-decode的源码,确认是这个问题,但是在onLaunch中移除atob方法,不顶用

@kala888
Copy link
Contributor Author

kala888 commented Mar 16, 2021

3.1.4 好像还没修复

@fozero
Copy link

fozero commented Jun 3, 2021

@kala888 请问你的解决了吗

@kala888
Copy link
Contributor Author

kala888 commented Jun 3, 2021

@fozero
Copy link

fozero commented Jun 3, 2021

@kala888 好吧,那只能这样了

@Chen-jj
Copy link
Contributor

Chen-jj commented Jun 16, 2021

我们在 Taro 内部删掉 window.atob

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Projects
None yet
3 participants