@tapni/auth 0.0.63 → 0.0.65
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.vite/manifest.json +5 -0
- package/dist/TapniAuth.es.js +11006 -2210
- package/dist/TapniAuth.umd.js +42 -12
- package/dist/web-L3jORB19.js +92 -0
- package/package.json +1 -1
- package/src/App.vue +1 -0
- package/src/install.js +2 -1
- package/src/mixins/auth.mixin.js +32 -6
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { WebPlugin as i } from "@capacitor/core";
|
|
2
|
+
class u extends i {
|
|
3
|
+
async initialize(e) {
|
|
4
|
+
const n = { version: "v17.0" };
|
|
5
|
+
return await this.loadScript(e.locale), FB.init(Object.assign(Object.assign({}, n), e));
|
|
6
|
+
}
|
|
7
|
+
loadScript(e) {
|
|
8
|
+
if (typeof document > "u")
|
|
9
|
+
return Promise.reject("document global not found");
|
|
10
|
+
const n = "fb";
|
|
11
|
+
if (document.getElementById(n))
|
|
12
|
+
return Promise.resolve();
|
|
13
|
+
const r = document.getElementsByTagName("head")[0], s = document.createElement("script");
|
|
14
|
+
return new Promise((o) => {
|
|
15
|
+
s.onload = () => o(), s.defer = !0, s.async = !0, s.id = n, s.src = `https://connect.facebook.net/${e ?? "en_US"}/sdk.js`, r.appendChild(s);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
async login(e) {
|
|
19
|
+
return new Promise((n, t) => {
|
|
20
|
+
FB.login((r) => {
|
|
21
|
+
r.status === "connected" ? n({
|
|
22
|
+
accessToken: {
|
|
23
|
+
token: r.authResponse.accessToken
|
|
24
|
+
}
|
|
25
|
+
}) : t({
|
|
26
|
+
accessToken: {
|
|
27
|
+
token: null
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}, { scope: e.permissions.join(",") });
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
async logout() {
|
|
34
|
+
return new Promise((e) => FB.logout(() => e()));
|
|
35
|
+
}
|
|
36
|
+
async reauthorize() {
|
|
37
|
+
return new Promise((e) => FB.reauthorize((n) => e(n)));
|
|
38
|
+
}
|
|
39
|
+
async getCurrentAccessToken() {
|
|
40
|
+
return new Promise((e, n) => {
|
|
41
|
+
FB.getLoginStatus((t) => {
|
|
42
|
+
if (t.status === "connected") {
|
|
43
|
+
const r = {
|
|
44
|
+
accessToken: {
|
|
45
|
+
applicationId: void 0,
|
|
46
|
+
declinedPermissions: [],
|
|
47
|
+
expires: void 0,
|
|
48
|
+
isExpired: void 0,
|
|
49
|
+
lastRefresh: void 0,
|
|
50
|
+
permissions: [],
|
|
51
|
+
token: t.authResponse.accessToken,
|
|
52
|
+
userId: t.authResponse.userID
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
e(r);
|
|
56
|
+
} else
|
|
57
|
+
n({
|
|
58
|
+
accessToken: {
|
|
59
|
+
token: null
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
async getProfile(e) {
|
|
66
|
+
const n = e.fields.join(",");
|
|
67
|
+
return new Promise((t, r) => {
|
|
68
|
+
FB.api("/me", { fields: n }, (s) => {
|
|
69
|
+
if (s.error) {
|
|
70
|
+
r(s.error.message);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
t(s);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
async logEvent() {
|
|
78
|
+
return Promise.resolve();
|
|
79
|
+
}
|
|
80
|
+
async setAutoLogAppEventsEnabled() {
|
|
81
|
+
return Promise.resolve();
|
|
82
|
+
}
|
|
83
|
+
async setAdvertiserTrackingEnabled() {
|
|
84
|
+
return Promise.resolve();
|
|
85
|
+
}
|
|
86
|
+
async setAdvertiserIDCollectionEnabled() {
|
|
87
|
+
return Promise.resolve();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
export {
|
|
91
|
+
u as FacebookLoginWeb
|
|
92
|
+
};
|
package/package.json
CHANGED
package/src/App.vue
CHANGED
|
@@ -124,6 +124,7 @@ export default {
|
|
|
124
124
|
EventBus.$on('ssoLogout',(data) => this.logout(data))
|
|
125
125
|
EventBus.$on('getLoggedInAccounts',(data) => this.getLoggedInAccounts(data))
|
|
126
126
|
EventBus.$on('refreshTokenAction',(data) => this.refreshTokenAction(data))
|
|
127
|
+
EventBus.$on('switchAccount',(data) => this.switchAccount(data))
|
|
127
128
|
},
|
|
128
129
|
methods: {
|
|
129
130
|
async init () {
|
package/src/install.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import App from "./App.vue";
|
|
2
|
-
import ReactiveStorage from '@tapni/capacitor-reactive-localstorage-vue3'
|
|
3
2
|
import Api from './services/Api'
|
|
3
|
+
import AuthMixin from './mixins/auth.mixin.js'
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
// Export the component by default
|
|
7
7
|
export default {
|
|
8
8
|
TapniAuth: App,
|
|
9
|
+
AuthMixin: AuthMixin,
|
|
9
10
|
install: (app, options) => {
|
|
10
11
|
if (options && options.API_ROOT) Api.setApiRootFromOptions(options.API_ROOT);
|
|
11
12
|
app.component('TapniAuth', App);
|
package/src/mixins/auth.mixin.js
CHANGED
|
@@ -25,6 +25,7 @@ export default {
|
|
|
25
25
|
appLanguage: "en",
|
|
26
26
|
token: "",
|
|
27
27
|
refreshToken: "",
|
|
28
|
+
refreshing: "",
|
|
28
29
|
loggedInUserId: "",
|
|
29
30
|
ssoUser: {},
|
|
30
31
|
ssoCompany: {},
|
|
@@ -240,8 +241,20 @@ export default {
|
|
|
240
241
|
// await this.registerDevice();
|
|
241
242
|
// if (Capacitor.isNativePlatform()) initPushNotifications();
|
|
242
243
|
},
|
|
243
|
-
async
|
|
244
|
+
async switchAccount(username) {
|
|
245
|
+
this.$storage.username = username;
|
|
246
|
+
this.$storage.UserId = this.loggedInAccounts[username].id;
|
|
247
|
+
this.setLoggedInUserId(this.loggedInAccounts[username].id);
|
|
248
|
+
this.setRefreshToken(this.loggedInAccounts[username].refreshToken);
|
|
249
|
+
await this.refreshTokenAction({ id: this.loggedInAccounts[username].id });
|
|
244
250
|
|
|
251
|
+
EventBus.$emit("ssoEvent", {
|
|
252
|
+
name: "switchAccount",
|
|
253
|
+
data: { lang: this.appLanguage, username },
|
|
254
|
+
});
|
|
255
|
+
},
|
|
256
|
+
async refreshTokenAction(data) {
|
|
257
|
+
this.refreshing = true;
|
|
245
258
|
const [err, response] = await to(
|
|
246
259
|
AuthService.refreshToken({
|
|
247
260
|
id: data.id,
|
|
@@ -258,6 +271,7 @@ export default {
|
|
|
258
271
|
if (response && response.data) {
|
|
259
272
|
this.setToken(response.data.token);
|
|
260
273
|
} else console.error('Invalid response setToken');
|
|
274
|
+
this.refreshing = false;
|
|
261
275
|
},
|
|
262
276
|
async login(data) {
|
|
263
277
|
const [err, response] = await to(AuthService.login(data, this.$storage));
|
|
@@ -472,17 +486,29 @@ export default {
|
|
|
472
486
|
}
|
|
473
487
|
},
|
|
474
488
|
getRefreshTokens() {
|
|
475
|
-
|
|
489
|
+
if (this.$storage && this.$storage.refreshTokens) this.$storage.refreshTokens.split(',')
|
|
490
|
+
else return [];
|
|
476
491
|
},
|
|
477
492
|
setRefreshToken(token) {
|
|
493
|
+
// Get all refresh tokens
|
|
478
494
|
let refreshTokens = this.getRefreshTokens();
|
|
479
|
-
if (token && !refreshTokens.includes(token)) refreshTokens.unshift(token);
|
|
480
|
-
else refreshTokens = refreshTokens.filter((t) => t !== this.refreshToken);
|
|
481
495
|
|
|
482
|
-
|
|
483
|
-
|
|
496
|
+
// If token exists, add to the top of the list
|
|
497
|
+
// If it doesn't exist, get the list without the current one - delete refresh
|
|
498
|
+
if (token) {
|
|
499
|
+
if (!refreshTokens.includes(token)) {
|
|
500
|
+
refreshTokens.unshift(token);
|
|
501
|
+
}
|
|
502
|
+
this.refreshToken = token;
|
|
503
|
+
} else {
|
|
504
|
+
refreshTokens = refreshTokens.filter((t) => t !== this.refreshToken);
|
|
505
|
+
|
|
506
|
+
// Set the first token as the new refresh token
|
|
507
|
+
if (refreshTokens.length >= 1) this.refreshToken = refreshTokens[0];
|
|
508
|
+
}
|
|
484
509
|
|
|
485
510
|
this.$storage.refreshTokens = refreshTokens.join(",");
|
|
511
|
+
|
|
486
512
|
EventBus.$emit("ssoEvent", { name: "setRefreshToken", data: token });
|
|
487
513
|
},
|
|
488
514
|
setToken(token) {
|