estou fazendo o curso do ANGULAR PARTE 2: AUTENTICAÇÃO, FORMS E LAZY LOADING https://cursos.alura.com.br/course/angular-autenticacao e no 3 topico 03. Usuário logado e proteção de rotas na primeira aula ele ensina como importa o jwt_decode porem me retorna esse erro
estou com problemas no .
import * as jwt_decode from 'jwt-decode';
. . aqui fala da a seguinte mensagem . .
✔ Browser application bundle generation complete.
Initial Chunk Files | Names | Raw Size
main.js | main | 142.85 kB |
runtime.js | runtime | 6.54 kB |
3 unchanged chunks
Build at: 2023-11-09T13:28:40.133Z - Hash: cbd41ed6367eb467 - Time: 392ms
Error: src/app/core/auth/auth.service.ts:24:33 - error TS2345: Argument of type 'string | null' is not assignable to parameter of type 'string'.
Type 'null' is not assignable to type 'string'.
24 this.UserService.setToken(authToken);
~~~~~~~~~
Error: src/app/core/user/user.service.ts:5:25 - error TS7016: Could not find a declaration file for module 'jwt-decode'. 'C:/Users/luizcarlos/Documents/GitHub/unicommerce-angular-web/unicommerce-angular-web/node_modules/jwt-decode/lib/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/jwt-decode` if it exists or add a new declaration (.d.ts) file containing `declare module 'jwt-decode';`
5 import jwt_decode from 'jwt-decode';
~~~~~~~~~~~~
× Failed to compile.
.
meu aquivo user.service.ts .
import { Injectable } from "@angular/core";
import { User } from "./user";
import { Subject } from "rxjs";
import { tokenService } from "../token/token.service";
import * as jwt_decode from 'jwt-decode';
@Injectable({ providedIn: 'root' })
export class UserService {
private userSubject = new Subject<User>();
constructor(private tokenService: tokenService) {
this.tokenService.hasToken() &&
this.decodeAndNotify();
}
setToken(token: string) {
this.tokenService.setToken(token);
this.decodeAndNotify();
}
getUser() {
return this.userSubject.asObservable();
}
private decodeAndNotify() {
const token = this.tokenService.getToken();
const user = jwt_decode(token) as User;
this.userSubject.next(user);
}
}
.
a versao que eu utilizo e a passada no video .