]我正在尝试使用Node.js和护照将Facebook登录集成到我的MEAN堆栈应用程序中,但出现以下错误。
我的passport.js和注册component.html位于两个不同的文件夹中。我没有解决该问题的方法。
下面是我的password.js
var FacebookStrategy = require('passport-facebook').Strategy;
var User =require('../models/User')
var session=require('express-session');
module.exports=function(app,passport){
app.use(passport.initialize());
app.use(passport.session());
app.use(session({secret: 'keyboard cat',resave: false,saveUninitialized:
true,cookie: { secure: false }}))
passport.serializeUser(function(user, done) {
done(null, user.id);
});
passport.deserializeUser(function(id, done) {
User.findById(id, function(err, user) {
done(err, user);
});
});
passport.use(new FacebookStrategy({
clientID: '456240351574071',
clientSecret: '0e8668a1e117c3488787bfd73de693e3',
callbackURL: "http://localhost:8080/auth/facebook/callback",
profileFields: ['id', 'displayName', 'photos', 'email']
},
function(accessToken, refreshToken, profile, done) {
console.log(profile);
//User.findOrCreate(..., function(err, user) {
// if (err) { return done(err); }
done(null, profile);
//});
}
));
app.get('/auth/facebook/callback', passport.authenticate('facebook', {
failureRedirect: '/login' }));
app.get('/auth/facebook', passport.authenticate('facebook', { scope:
'email' }));
return passport;
}
下面是我的注册组件。html
<mat-card class="example-card">
<mat-card-header>
<mat-card-title>REGISTER</mat-card-title>
</mat-card-header>
<mat-card-content>
<form class="example-form">
<table class="example-full-width" cellspacing="0">
<tr>
<td>
<mat-form-field class="example-full-width">
<input matInput placeholder="Name" [(ngModel)]="name" name="name"
required>
</mat-form-field>
</td>
</tr>
<tr>
<td><mat-form-field class="example-full-width">
<input matInput placeholder="EmailAddress"
[(ngModel)]="emailAddress" name="emailAddress" required>
</mat-form-field></td>
</tr>
<tr>
<td>
<mat-radio-group>
<mat-radio-button value="1">Male</mat-radio-button>
<mat-radio-button value="2">Female</mat-radio-button>
</mat-radio-group>
</td>
</tr>
<tr>
<td><mat-form-field class="example-full-width">
<input matInput placeholder="Password" [(ngModel)]="password"
type="password" name="password" required>
</mat-form-field></td>
</tr>
</table>
</form>
<mat-spinner [style.display]="showSpinner ? 'block' : 'none'"></mat-
spinner>
</mat-card-content>
<mat-card-actions>
<button mat-raised-button (click)="signUp()" color="primary">Sign
Up</button>
<a href="/auth/facebook" target="_blank"><button type="button"
class="btn btn-success"> Facebook </button></a>
<button mat-raised-button (click)="socialSignIn('google')"
color="primary">Sign in with Google</button>
</mat-card-actions>
</mat-card>
和以下是我在控制台中遇到的错误: core.js:1673错误错误:未捕获(承诺):错误:无法匹配任何路由。网址区隔:“ auth / facebook” 错误:无法匹配任何路线。网址段:“ auth / facebook”