File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,30 @@ export const getAccessToken = async () => {
41
41
return cookie ?. value ;
42
42
} ;
43
43
44
+ export const checkin = async ( ) => {
45
+ const token = await getAccessToken ( ) ;
46
+ if ( ! token ) {
47
+ return ;
48
+ }
49
+
50
+ // Don't check in more than once every 12 hours to reduce amount of requests
51
+ const { lastCheckin } = await storage . local . get ( 'lastCheckin' ) ;
52
+ if ( lastCheckin && Date . now ( ) - lastCheckin < 1000 * 60 * 60 ) {
53
+ return ;
54
+ }
55
+
56
+ const res = await fetch ( `${ gkApiUrl } /browser-extension/checkin` , {
57
+ headers : {
58
+ Authorization : `Bearer ${ token } ` ,
59
+ } ,
60
+ method : 'POST' ,
61
+ } ) ;
62
+
63
+ if ( res . ok ) {
64
+ void storage . local . set ( { lastCheckin : Date . now ( ) } ) ;
65
+ }
66
+ } ;
67
+
44
68
export const fetchUser = async ( ) => {
45
69
const token = await getAccessToken ( ) ;
46
70
if ( ! token ) {
Original file line number Diff line number Diff line change 3
3
import { PersistQueryClientProvider } from '@tanstack/react-query-persist-client' ;
4
4
import React from 'react' ;
5
5
import { createRoot } from 'react-dom/client' ;
6
- import { postEvent } from '../gkApi' ;
6
+ import { checkin , postEvent } from '../gkApi' ;
7
7
import { Popup } from './components/Popup' ;
8
8
import { asyncStoragePersister , queryClient } from './queryClient' ;
9
9
@@ -17,6 +17,7 @@ function main() {
17
17
) ;
18
18
19
19
void postEvent ( 'browserExtensionPopupOpened' ) ;
20
+ void checkin ( ) ;
20
21
}
21
22
22
23
main ( ) ;
You can’t perform that action at this time.
0 commit comments