Ich habe eine typische Web-App mit einem Login-Formular und ich versuche, feedsjs für das Back-End zu verwenden, um den Benutzer über Ruhe zu authentifizieren. Ich benutze Winkel 4 für das vordere Ende.Authentifizierung in fetahersjs/angular 4
Frontend Auth Service in Angular 4:
import { Injectable } from '@angular/core';
import { HttpHeaders, HttpClient } from '@angular/common/http';
import 'rxjs/add/operator/toPromise';
@Injectable()
export class AuthService {
private BASE_URL: string = 'http://localhost:3030';
private headers: HttpHeaders = new HttpHeaders({'Content-Type': 'application/json'});
constructor(private http: HttpClient) {}
login(user): Promise<any> {
let url: string = `${this.BASE_URL}/authentication`;
return this.http.post(url, user, {headers: this.headers}).toPromise();
}
}
config/default.json in Back-End:
"authentication": {
"secret": "my-secret",
"strategies": [
"jwt",
"local"
],
"path": "/authentication",
"service": "users",
"jwt": {
"header": {
"typ": "access"
},
"audience": "https://yourdomain.com",
"subject": "anonymous",
"issuer": "feathers",
"algorithm": "HS256",
"expiresIn": "1d"
},
"local": {
"entity": "teams",
"usernameField": "email",
"passwordField": "password"
}
}
authentication.js in Back-End-
const authentication = require('feathers-authentication');
const jwt = require('feathers-authentication-jwt');
const local = require('feathers-authentication-local');
module.exports = function() {
const app = this;
const config = app.get('authentication');
// Set up authentication with the secret
app.configure(authentication(config));
app.configure(jwt());
app.configure(local());
app.service('authentication').hooks({
before: {
create: [
authentication.hooks.authenticate(config.strategies)
],
remove: [
authentication.hooks.authenticate('jwt')
]
}
});
};
Mit dem obigen bekomme ich 404 für den/Authentifizierungsendpunkt. Muss ich den Authentifizierungsendpunkt manuell erstellen oder erstellt featherjs das für mich? Können Sie ein Beispiel geben?
Warum wird Angular überhaupt erwähnt? Die Frage ist spezifisch für das Backend und kann wahrscheinlich mit Postman oder so debuggt und repliziert werden. Ja, '/ authentication' sollte so funktionieren. Überprüfen Sie, ob das Auth-Plugin in der Node-Konsole keine Fehler enthält. Erwägen Sie die Bereitstellung von http://stackoverflow.com/help/mcve (z. B. ein Repo), da Federpaketversionen von Bedeutung sind. – estus