gpt4 book ai didi

javascript - Meteor和铁路由器,等待登录

转载 作者:行者123 更新时间:2023-11-29 10:43:58 25 4
gpt4 key购买 nike

我有一个login 路由。我在行动前挂上了这个钩子(Hook):

onBeforeAction: function() {

console.log(Meteor.user())
console.log(this.route.name)

// If the user is not logged and if we are not on the login page
// Redirect the user to the login page
if( !Meteor.user() && this.route.name !== 'login' ) {
Router.go('login');
};

// If the user is logged, take him out of the login page
if( Meteor.user() && this.route.name === 'login' ) {
Router.go('newsletters.index');
};
}

但是及时登录呢?

如果 Meteor.loggingIn() 为真,我想让路由器等待。 waitOn 与订阅有关,但没有起作用。

我很确定之前还有其他人这样做过:)

最佳答案

我使用...
Iron-Router ($meteor add cmather:iron-router) 和
Accounts-entry ($meteor添加 joshowens:accounts-entry)。

你可以在Git Hub上查看
https://github.com/Differential/accounts-entry
https://github.com/EventedMind/iron-router

对于配置,您必须在客户端文件夹中创建一个存档,例如 config.js

Meteor.startup(function () {
AccountsEntry.config({
logo: 'logo.png', // if set displays logo above sign-in options
homeRoute: '/', // mandatory - path to redirect to after sign-out
dashboardRoute: '/dashboard', // mandatory - path to redirect to after successful sign-in
profileRoute: 'profile',
passwordSignupFields: 'USERNAME_AND_EMAIL',
language: 'en',
showOtherLoginServices: true, // Set to false to hide oauth login buttons on the signin/signup pages. Useful if you are using something like accounts-meld or want to oauth for api access
extraSignUpFields: [{ // Add extra signup fields on the signup page
field: "name", // The database property you want to store the data in
name: "This Will Be The Initial Value", // An initial value for the field, if you want one
label: "Full Name", // The html lable for the field
placeholder: "John Doe", // A placeholder for the field
type: "text", // The type of field you want
required: true // Adds html 5 required property if true
}]
});
});

之后,您必须在文件夹 lib/router.js 中添加以下代码,

var mustBeSignedIn = function(pause) {
AccountsEntry.signInRequired(this);
};

Router.onBeforeAction(mustBeSignedIn, {
except: ['entrySignIn', 'entrySignUp', 'entryForgotPassword', 'layout', 'home']
});

这是我此时使用的解决方案。

关于javascript - Meteor和铁路由器,等待登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23158609/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com