I am using universal-starter as backbone.
When my client starts, it read a token about user info from localStorage.
@Injectable()
export class UserSe
I don't think this is a good solution, but I was stucked with the same problem using aspnetcore-spa generator and solved it this way:
@Injectable()
export class UserService {
foo() {}
bar() {}
loadCurrentUser() {
if (typeof window !== 'undefined') {
const token = localStorage.getItem('token');
}
// do other things
};
}
This condition prevents client code from running on the server-side where 'window' object doesn't exist.