2013-07-24 22 views
3

好,所以當我第一次註冊後我的應用程序啓動時,我想將用戶重定向到不同的頁面。如何僅將新用戶重定向到不同的頁面一次?

在我的服務器代碼,我有這個

Accounts.onCreateUser(function(options, user) { 
Hooks.onCreateUser = function() { 
Meteor.Router.to('/newUser'); 
    } 
}); 

但我想,所以我有這個在我的客戶端代碼將用戶重定向到另一個頁面,如果他們已經在更多然後一次,它總是默認爲客戶端,我做錯了什麼?

Hooks.onLoggedIn = function() { 
Meteor.Router.to('/new'); 
} 

回答

2

如果你要一個簽名的用戶重定向,只需設置用戶對象表示他是否被重定向內的標誌:

Hooks.onLoggedIn = function(){ 
    if(!Meteor.user()) return; 
    if(!Meteor.user().returning) { 
    Meteor.users.update(Meteor.userId(), {$set: {returning: true}}); 
    Meteor.Router.to('/new'); 
    } 
} 

確保發佈&訂閱用戶採集的returning場!


如果您想要提供與所有訪客類似的功能,請使用cookies。

Hooks.onLoggedIn = function(){ 
    if(!Cookie.get('returning')) { 
    Cookie.set('returning', true); 
    Meteor.Router.to('/new'); 
    } 
} 

這裏的方便的程序包爲:https://atmosphere.meteor.com/package/cookies

+0

嗯感謝,但即時尋找一些不同的東西,我認爲還是需要多一點幫助,當第一次在用戶登錄,我想消息出現在/新屏幕上,但在後續登錄中,我不希望該消息出現,所以我的困境是試圖找出如何使這一次的事情 – flylib

0

創建集 'ExistingUsers' 跟蹤。

if (Meteor.isClient) { 
    Deps.autorun(function() { 
    if(Meteor.userId()) 
//will run when a user logs in - now check if userId is in 'ExistingUsers' 
//If not display message and put userId in 'ExistingUsers' 
}); 

或者添加字段「SeenMessage」以用戶採集

相關問題