Autenticação no Angular2 #1237
Unanswered
maycon3
asked this question in
Perguntas e Respostas
Replies: 2 comments
-
@maycon3 Está bem dificil de ler, adicione o código dentro da sintaxe de código do markdown para facilitar a leitura e possivel ajuda :) |
Beta Was this translation helpful? Give feedback.
0 replies
-
@lfeh foi mal sou novo!!!
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Boa tarde a todos!
Estou usando o JWT em um projeto que estou desenvolvendo em Angular e java. Sendo que chega na parte do angular em autenticar , ele manda as informações certinho para o servidor e autentica sendo que na parde do console ele recebe o valor do token null, pesquisei em vários site mas não obtive responta para o que esta ocorrendo. Alguém pode me ajudar ?
Sou novo nessa linguagem.
import { API_CONFIG } from './../configuracao/api.config';
import { CredenciaisDTO } from './../modelos/credenciais.tdo';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
@Injectable()
export class AuthService {
constructor(public http: HttpClient) { }
autenticacao(creds :CredenciaisDTO){
return this.http.post(
${API_CONFIG.baseUrl}/login
,creds,
{
observe : 'response',
responseType : 'text'
});
}
}
import { Injectable ,EventEmitter } from '@angular/core';
import { CredenciaisDTO } from '../modelos/credenciais.tdo';
import { Router } from '@angular/router';
import { AuthService } from './auth.service';
@Injectable()
export class SharedService {
private usuarioAutenticado : boolean = false;
mostrarMenuEmitter = new EventEmitter();
constructor(private router : Router,
public auth : AuthService) {}
fazerLogin(creds : CredenciaisDTO){
this.auth.autenticacao(creds)
.subscribe(response =>{
console.log(response.headers.get('Authorization'));
this.usuarioAutenticado = true;
this.mostrarMenuEmitter.emit(true);
this.router.navigate(['/']);
},
error =>{
this.usuarioAutenticado = false;
this.mostrarMenuEmitter.emit(false);
});
}
}
import { Component, OnInit } from '@angular/core';
import { SharedService } from '../../../services/shared.service';
import { CredenciaisDTO } from '../../../modelos/credenciais.tdo';
@component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {
creds : CredenciaisDTO = {
email: "",
senha:""
}
constructor(private shared : SharedService ) {
}
ngOnInit() {
}
login(){
this.shared.fazerLogin(this.creds);
}
}
Beta Was this translation helpful? Give feedback.
All reactions