spring boot - angular springboot login JWT - Stack Overflow

After login, I stored token and userRole in localStorage... I tried to inject a random token (without l

After login, I stored token and userRole in localStorage... I tried to inject a random token (without login) in localStorage via navigator and then, I can get access to the restricted page...

I want to prevent this security issue... I thought about a database where to store my token directly after the login and then compare it with the one that exists in localStorage.

isAuthenticated():boolean{
 
       const token = localStorage.getItem('token');

        return !!token;
  }

After login, I stored token and userRole in localStorage... I tried to inject a random token (without login) in localStorage via navigator and then, I can get access to the restricted page...

I want to prevent this security issue... I thought about a database where to store my token directly after the login and then compare it with the one that exists in localStorage.

isAuthenticated():boolean{
 
       const token = localStorage.getItem('token');

        return !!token;
  }
Share Improve this question edited Jan 31 at 9:40 Luca 6884 silver badges16 bronze badges asked Jan 29 at 11:36 user29415755user29415755 1 1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Bot Commented Jan 29 at 15:52
Add a comment  | 

1 Answer 1

Reset to default 0

A token is used to restrict access to the calls to the Spring back-end. All your code is doing is returning true for any token. There is no call to the back-end.

The correct configuration of Spring Security is required in the back-end - it may already be setup. Spring security will validate the token and check roles before permitting the call to start.

Also you need to add the Authorization Bearer header to each call to the back-end.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745301301a4621451.html

相关推荐

  • spring boot - angular springboot login JWT - Stack Overflow

    After login, I stored token and userRole in localStorage... I tried to inject a random token (without l

    7小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信