forked from jramer/accounts-apple
-
Notifications
You must be signed in to change notification settings - Fork 4
/
apple.js
39 lines (36 loc) · 1.18 KB
/
apple.js
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
/* global Apple */
Accounts.oauth.registerService("apple");
if (Meteor.isClient) {
const loginWithApple = async (options, callback) => {
// support a callback without options
if (!callback && typeof options === "function") {
callback = options;
options = null;
}
const credentialRequestCompleteCallback = Accounts.oauth.credentialRequestCompleteHandler(
callback
);
await Apple.requestCredential(
options,
credentialRequestCompleteCallback,
callback
);
};
Accounts.registerClientLoginFunction("apple", loginWithApple);
Meteor.loginWithApple = (...args) =>
Accounts.applyLoginFunction("apple", args);
} else {
Accounts.addAutopublishFields({
forLoggedInUser: Apple.whitelistedFields
.concat(["accessToken", "expiresAt"])
.map(
(subfield) => `services.apple.${subfield}` // don't publish refresh token
),
forOtherUsers:
// even with autopublish, no legitimate web app should be
// publishing all users' emails
Apple.whitelistedFields
.filter((field) => field !== "email" && field !== "verified_email")
.map((subfield) => `services.apple.${subfield}`),
});
}