This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function removeAccessTokenFromUrl() { | |
const { history, location } = window | |
const { search } = location | |
if (search && search.indexOf('access_token') !== -1 && history && history.replaceState) { | |
// remove access_token from url | |
const cleanSearch = search.replace(/(\&|\?)access_token([_A-Za-z0-9=\.%]+)/g, '').replace(/^&/, '?') | |
// replace search params with clean params | |
const cleanURL = location.toString().replace(search, cleanSearch) | |
// use browser history API to clean the params | |
history.replaceState({}, '', cleanURL) |