Skip to content

Commit 4b67d4b

Browse files
committed
0.1.13
1 parent 076ef26 commit 4b67d4b

File tree

3 files changed

+56
-4
lines changed

3 files changed

+56
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pam-react-native",
3-
"version": "0.1.11",
3+
"version": "0.1.13",
44
"description": "Pam SDK for React Native",
55
"source": "./src/index.tsx",
66
"main": "./lib/commonjs/index.js",

src/httpclient.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Platform } from 'react-native';
2+
13
export class HTTPClient {
24
private baseUrl: string;
35

@@ -11,7 +13,10 @@ export class HTTPClient {
1113
public async get(endpoint: string, headers: { [key: string]: string }) {
1214
const response = await fetch(`${this.baseUrl}${endpoint}`, {
1315
method: 'GET',
14-
headers: headers || {},
16+
headers: {
17+
platform: Platform.OS,
18+
...(headers ?? {}),
19+
},
1520
});
1621

1722
if (!response.ok) {
@@ -26,6 +31,7 @@ export class HTTPClient {
2631
method: 'PUT',
2732
headers: {
2833
'Content-Type': 'application/json',
34+
'platform': Platform.OS,
2935
},
3036
body: JSON.stringify(body),
3137
});
@@ -48,6 +54,7 @@ export class HTTPClient {
4854
method: 'POST',
4955
headers: {
5056
'Content-Type': 'application/json',
57+
'platform': Platform.OS,
5158
...headers,
5259
},
5360
credentials: cookieLess ? 'omit' : 'include',

src/index.tsx

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,56 @@ export class Pam {
163163
}
164164

165165
static async userLogin(loginId: string) {
166-
return Pam.shared?.userLogin(loginId);
166+
const deviceToken =
167+
await Pam._instance.storage?.getLocalStorage('deviceToken');
168+
const mediaKey =
169+
await Pam._instance.storage?.getLocalStorage('push_media_key');
170+
if (mediaKey) {
171+
let payload: Record<string, any> = { _delete_media: mediaKey };
172+
await Pam.shared?.track('delete_media', payload);
173+
}
174+
const loginResp = await Pam.shared?.userLogin(loginId);
175+
if (deviceToken) {
176+
await Pam.updatePushNotificationToken(deviceToken);
177+
}
178+
179+
return loginResp;
167180
}
168181

169182
static async userLogout() {
170-
return Pam.shared?.userLogout();
183+
const deviceToken =
184+
await Pam._instance.storage?.getLocalStorage('deviceToken');
185+
const mediaKey =
186+
await Pam._instance.storage?.getLocalStorage('push_media_key');
187+
if (mediaKey) {
188+
let payload: Record<string, any> = { _delete_media: mediaKey };
189+
await Pam.shared?.track('delete_media', payload);
190+
}
191+
192+
const logoutResp = await Pam.shared?.userLogout();
193+
194+
if (deviceToken) {
195+
await Pam.updatePushNotificationToken(deviceToken);
196+
}
197+
return logoutResp;
198+
}
199+
200+
static updatePushNotificationToken(deviceToken: string) {
201+
let mediaKey = '';
202+
if (Platform.OS === 'ios') {
203+
if (__DEV__) {
204+
deviceToken = `_${deviceToken}`;
205+
}
206+
mediaKey = 'ios_notification';
207+
} else {
208+
mediaKey = 'android_notification';
209+
}
210+
let payload: Record<string, any> = {};
211+
payload[mediaKey] = deviceToken;
212+
213+
Pam.shared?.track('save_push', payload);
214+
Pam._instance.storage?.setLocalStorage('deviceToken', deviceToken);
215+
Pam._instance.storage?.setLocalStorage('push_media_key', mediaKey);
171216
}
172217

173218
static async loadConsentStatus(consentMessageId: string) {

0 commit comments

Comments
 (0)