16
How can we use authentication token if cookie is blocked by user.
Authentication Token is a non human readable text which contains some encrypted data. It is used to authenticate user for API access.
read-more-about-it
read-more-about-it
A single-page application (SPA) is a web application or website that interacts with the user by dynamically rewriting the current web page with new data from the web server, instead of the default method of a web browser loading entire new pages.
wiki
wiki
id
and password
token
if user is authenticatedhttp
request, user sends token
as header, query-parameter or by whatever way to authenticate with API's.You can read about advantages and disadvantages over here
All the above storage mechanism are depended on
cookie
. If cookie is blocked by user then your application will not function properly or it might break.Your application will break here if you are not handeling them with
try and catch
// set
try{
localStorage.token = "...";
}catch(e){
//
}
// get
try{
console.log(localStorage.token)
}catch(e){
//
}
If you are handeling web storage with
try and catch
then either you can prompt user to enable cookie or leave user as not authenticated. If user went on any other page and that page require authentication then again user has to come at signin page.Process continue...
Sign-in page > Authenticated page
Authenticated page -> Sign-in page
Sign-in page > Authenticated page
Authenticated page -> Sign-in page
....
We have currently two solutions to this problem
Window
global variableIf you are using redux then you need to write a lot of code.
If you are using window then you don't need to write...
(token)
window.token = token