Skip to content

Commit d3d3142

Browse files
committed
Restore expo token on boot if has permissions
1 parent 60499ef commit d3d3142

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

packages/expo/src/modules/push/KnockExpoPushNotificationProvider.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,23 @@ const InternalKnockExpoPushNotificationProvider: React.FC<
188188
[knockClient],
189189
);
190190

191+
useEffect(() => {
192+
const fetchExpoTokenIfNeeded = async () => {
193+
const { status: existingStatus } =
194+
await Notifications.getPermissionsAsync();
195+
if (existingStatus === "granted" && Device.isDevice) {
196+
try {
197+
const token = await getExpoPushToken();
198+
setExpoPushToken(token ? token.data : null);
199+
} catch (error) {
200+
console.error(`[Knock] Error getting expo push token:`, error);
201+
}
202+
}
203+
};
204+
205+
fetchExpoTokenIfNeeded();
206+
}, []);
207+
191208
useEffect(() => {
192209
Notifications.setNotificationHandler({
193210
handleNotification:

0 commit comments

Comments
 (0)