I need assistance with adding the Remember Me functionality to a login form in an Angular application. Could someone please provide guidance on how to achieve this? Your help would be highly appreciated! Thank you in advance! Below is my login.ts file:
ngOnInit() {
this.form = this.formBuilder.group({
email: ['', [Validators.required, Validators.email] ],
password: ['', Validators.required]
});
}
get f(){
return this.form.controls;
}
onSubmit() {
this.submitted = true;
this.accountService.login(this.f.email.value, this.f.password.value)
}
Additionally, here is my account.service.ts file:
export class AccountService {
private accountSubject: BehaviorSubject<Account>;
public account: Observable<Account>;
constructor(
private router: Router,
private http: HttpClient
) {
this.accountSubject = new BehaviorSubject<Account>(null);
this.account = this.accountSubject.asObservable();
}
public get accountValue(): Account {
return this.accountSubject.value;
}
login(email: string, password: string) {
return this.http.post<any>(`${baseUrl}/authenticate`, { email, password }, { withCredentials: true })
.pipe(map(account => {
this.accountSubject.next(account);
return account;
}));
}
logout() {
this.http.post<any>(`${baseUrl}/revoke-token`, {}, { withCredentials: true }).subscribe();
this.accountSubject.next(null);
this.router.navigate(['/account/login']);
}
}