Repository navigation
Expand file tree
/
Copy pathroutes.js
More file actions
70 lines (62 loc) · 1.43 KB
/
Copy pathroutes.js
File metadata and controls
70 lines (62 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
Router.configure({
layoutTemplate: 'Main',
loadingTemplate: 'Loading',
notFoundTempalte: 'NotFound',
load: function () {
$('html, body').animate({ scrollTop: 0 }, 400);
$('.content').hide().fadeIn(500);
}
});
var redirectIfNotLoggedIn = function () {
var user = Meteor.user();
if (!user) {
if (!Meteor.loggingIn()) {
Router.go('Login');
}
} else {
// If logged in, make sure we have a FacebookAccount for this user
MeteorFB.onReady(function () {
MeteorFB.getFacebookId(function (facebookId) {
if (!FacebookAccounts.findOne({facebook_id: facebookId})) {
FacebookAccounts.insert({
facebook_id: facebookId,
user_id: user._id
});
}
});
});
}
}
Router.map(function () {
this.route('Login', {
path: '/',
onBeforeAction: function () {
if (Meteor.user()) {
Router.go('Home');
}
}
});
this.route('Home', {
onBeforeAction: redirectIfNotLoggedIn,
});
this.route('ShoppingList', {
path: '/list/:_id',
onBeforeAction: redirectIfNotLoggedIn,
data: function () {
return { id: this.params._id };
}
});
this.route('GoShopping', {
path: '/goshop/:_id',
onBeforeAction: redirectIfNotLoggedIn,
data: function () {
return { id: this.params._id };
}
});
this.route('PostItem', {
action: function () {
debugger
console.log(this);
}
});
});