-
Notifications
You must be signed in to change notification settings - Fork 3
/
meteor-user.html
81 lines (70 loc) · 1.62 KB
/
meteor-user.html
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
71
72
73
74
75
76
77
78
79
80
81
<!--
This element manage current user.
Example:
<meteor-user logged-in={{conn}} user={{user}}></meteor-user>
<span hidden$="{{!conn}}" >UserName : {{user.profile.name}}</span>
-->
<script>
Polymer({
is: 'meteor-user',
properties: {
/**
* Get the current user id, or null if no user is logged in.
*/
id: {
type: String,
notify: true,
readOnly: true
},
/**
* Get the current user record, or null if no user is logged in.
*/
user : {
type : Object,
notify: true,
readOnly: true
},
/**
* Helper on user is logged in or not
*/
loggedIn: {
type: Boolean,
notify: true,
readOnly: true,
value: false
},
/**
* True if a login method (such as Meteor.loginWithPassword, Meteor.loginWithFacebook, or Accounts.createUser) is currently in progress.
*/
loggingIn: {
type: Boolean,
notify: true,
readOnly: true,
value: false
},
},
/**
* Log the user out.
*/
logout : function() {
Meteor.logout();
},
ready: function() {
this._userComputation = Tracker.autorun(function() {
var user = Meteor.user();
this._setId(user ? user._id : null);
this._setUser(user);
this._setLoggedIn(user != null);
}.bind(this));
this._loggingInComputation = Tracker.autorun(function() {
this._setLoggingIn(Meteor.loggingIn());
}.bind(this));
},
detached: function() {
if (this._userComputation)
this._userComputation.stop();
if (this._loggingInComputation)
this._loggingInComputation.stop();
}
});
</script>