Skip to content

Trouble with the AuthService > refreshToken #2

@kosuh

Description

@kosuh

Hello,

I allow myself to contact you because after setting up your solution everything works fine except that I block on the method refreshToken AuthService

When I make my request in http to retrieve the new token, the return executes before the request replies.

I am not very experienced in Angular so I think the solution is not difficult.

AuthService.ts

refreshToken(): Observable<any> {
		let url: string = environment.API + "/auth/token/refresh";
		let jwt = JSON.parse(localStorage.getItem('jwt'));
		const query = {
			'refresh_token': jwt.refresh_token
		}
		this.http.post(url, query).pipe(
			map((newtoken) => {
				localStorage.setItem('jwt', JSON.stringify(newtoken));
				jwt = JSON.parse(localStorage.getItem('jwt'));
				this.authTokenNew = jwt.token;
		}));

		this.currentToken = this.authTokenNew;

		return observableOf(this.authTokenNew).pipe(delay(200));
	}

Do you have a solution for me please ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions