index.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOnsiaWQiOiI2MWE0ZGIyOWM3NTBjMTJiYTZiYTQwMjIiLCJsb2dpbiI6ImVxd2VxZXdldyIsImFjbCI6WyI2MWE0ZGIyOWM3NTBjMTJiYTZiYTQwMjIiLCJ1c2VyIl19LCJpYXQiOjE2MzgxOTQ1NzZ9.Pi1GO6x7wdNrIrUKCQT-32-SsqmgFY-oFDrrXmw74-8'
  2. // JSON.parse(atob(token.split('.')[1]))
  3. // let qqq = 'fdhfakfalfjskgfsdadasdasdasdasdadfsdfkarieqfowerdaesfa'
  4. // function checkSum(str) {
  5. // let res = 0
  6. // for (let letter of str) {
  7. // res += letter.charCodeAt()
  8. // }
  9. // return res
  10. // }
  11. // console.log(checkSum(qqq))
  12. // function sign(data, salt) {
  13. // const json = JSON.stringify(data)
  14. // const sum = checkSum(json + salt)
  15. // return json + sum
  16. // }
  17. // function verify(signed, salt) {
  18. // const json = signed.slice(0, signed.lastIndexOf('}') + 1)
  19. // const tokenSum = + signed.slice(signed.lastIndexOf('}') + 1)
  20. // const sum = checkSum(json + salt)
  21. // console.log(json, tokenSum, sum)
  22. // return sum === tokenSum
  23. // }
  24. localStorage.authToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOnsiaWQiOiI2MWE0ZGIyOWM3NTBjMTJiYTZiYTQwMjIiLCJsb2dpbiI6ImVxd2VxZXdldyIsImFjbCI6WyI2MWE0ZGIyOWM3NTBjMTJiYTZiYTQwMjIiLCJ1c2VyIl19LCJpYXQiOjE2MzgxOTk4NDl9.wzpQZ3KjywbNSfCt0Z_dua2AIrADL-ID-4Rs2cVnq0Q"
  25. const originalFetch = fetch;
  26. fetch = (url, params={headers:{}}) => {
  27. params.headers.Authorization = "Bearer " + localStorage.authToken
  28. return originalFetch(url, params)
  29. }