Why my token get shorten automatically when I try to access it from the url?

Viewed 24

I got an app running on the url with query parameter

http://localhost:4205/?token=rO0ABXdJAAlhZG1pbi13ZWIAAAGBQW7DvQAAAAAAJDQwNDVkNWU2LWUwYzQtNDkyOC1iZjI5LTI0ZTgwOGNkZDIyZQAAAAAAAeecAAAAAA==#LxbtdufwktgB49NKgqDwH6yisPjSRHV/k0bXUt/0+z3rLB8vFr3uWX39pzC6uVz1KgVw89S9Vku7cQp1Q1YZrQ==

So since I am using react Router DOM. I got the token by using a method from react Router DOM

const tokenFromQuery = searchParams.get('token');

this will search for a query token.

What happen is that when I try to console.log the token got from tokenFromQuery & which I copy from url origin token. These got different lengths

console.log(tokenToPass.length);

console.log('rO0ABXdJAAlhZG1pbi13ZWIAAAGBQW7DvQAAAAAAJDQwNDVkNWU2LWUwYzQtNDkyOC1iZjI5LTI0ZTgwOGNkZDIyZQAAAAAAAeecAAAAAA==#LxbtdufwktgB49NKgqDwH6yisPjSRHV/k0bXUt/0+z3rLB8vFr3uWX39pzC6uVz1KgVw89S9Vku7cQp1Q1YZrQ=='.length);

The result is 108 for token to pass and 197 from original token.

Why this happen? and

1 Answers

because all after # in ..AAAAAA==#Lxbtdufw.. is no longer part of the variable in the url, then the token variable in the url is read until before the character #

you can encode the url before put it in the url, encodeURIComponent and then decode when you want to use it decodeURIComponent

Related