Save service data while refreshing page

Discussão em 'Angular' iniciado por Kepes, Agosto 2, 2025.

  1. Kepes

    Kepes Guest

    I have a simple service, that holds user credential ( username and password via btoa ):

    @Injectable({
    providedIn: 'root'
    })
    export class UserService {
    userCredentials = '';
    }


    initializing fileds while loggin in:

    this.userService.userCredentials = btoa(this.user.username + ':' + this.user.password);


    I use this credentials in my backend spring boot app, to authenticate user etc.:

    @RequestMapping("/core/user")
    public Principal user(HttpServletRequest request) {
    String authToken = request.getHeader("Authorization").substring("Basic".length()).trim();
    return () -> new String(Base64.getDecoder().decode(authToken)).split(":")[0];
    }


    How to handle page refresh in such way as not to lose data in service? Holding such data in session storage is very unsafe, so I don't want to store user credential in localStorage/sessionStorage.

    Continue reading...

Compartilhe esta Página