简体   繁体   中英

How to keep session alive in angular (login foncionality)

i using angular (typescript) and Spring boot (Java) How i can keep session alive when i in the admin mode (login) just the code or the fucntion to do that and thanks

this is the service code to get all account

i know it's not secure but just for learn lol

public getAdmin(): Observable<Admin[]>{
    return this.http.get<Admin[]>(`${this.apiServerUrl}/admin/all`);
  }

The angular app has keep token and user details in order to keep commnication with the server. This token usually will be save in localStorage which is not angular related.

You can create a service like this:

@Injectable
export class MyService {

  constructor() { }

 public saveUser(user) {   
    localStorage .setItem(U_KEY, JSON.stringify(user));    
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM