Looking for a solution to a token storage issue, my initial thought is that interfaces might be the way to go. Presently, my login code looks like this:
import { Component } from '@angular/core';
import { FormBuilder } from '@angular/forms';
import { HttpClient } from '@angular/common/http';
interface User {
success: {
id: number;
role: string;
accessToken: string;
refreshToken: string;
lifetime: {
epoch: number;
timeZone: number;
}
}
}
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css'],
})
export class LoginComponent {
constructor( private fb: FormBuilder, private http: HttpClient ) { }
loginInfo = this.fb.group({
email: [''],
password: ['']
})
onSubmit() {
this.http.post<User>('', this.loginInfo.value)
.subscribe(x => localStorage.setItem("currentUser",JSON.stringify(x)))
};
}
The challenge lies in dealing with refreshToken and accessToken coming in as Base64 encoded strings, which I believe can only be resolved using the atob() function. Is there a way to address this within the interface?
I'm aware the code snippet below doesn't function, but it aims to clarify the goal:
interface User {
success: {
id: number;
role: string;
accessToken: atob(string);
refreshToken: atob(string);
lifetime: {
epoch: number;
timeZone: number;
}
}
}