Skip to content

Commit e565a6c

Browse files
committed
Set last online upon user creation
1 parent c1fe700 commit e565a6c

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

backend/api/src/create-user.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {insert} from 'shared/supabase/utils'
1414
import {convertPrivateUser, convertUser} from 'common/supabase/users'
1515
import {getBucket} from "shared/firebase-utils";
1616
import {sendWelcomeEmail} from "email/functions/helpers";
17+
import {setLastOnlineTimeUser} from "api/set-last-online-time";
1718

1819
export const createUser: APIHandler<'create-user'> = async (
1920
props,
@@ -134,6 +135,11 @@ export const createUser: APIHandler<'create-user'> = async (
134135
} catch (e) {
135136
console.error('Failed to sendWelcomeEmail', e)
136137
}
138+
try {
139+
await setLastOnlineTimeUser(auth.uid)
140+
} catch (e) {
141+
console.error('Failed to set last online time', e)
142+
}
137143
}
138144

139145
return {

backend/api/src/set-last-online-time.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ export const setLastOnlineTime: APIHandler<'set-last-online-time'> = async (
66
auth
77
) => {
88
if (!auth || !auth.uid) return
9+
await setLastOnlineTimeUser(auth.uid)
10+
// console.log('setLastOnline')
11+
}
912

13+
14+
export const setLastOnlineTimeUser = async (userId: string) => {
1015
const pg = createSupabaseDirectClient()
1116
await pg.none(`
1217
INSERT INTO user_activity (user_id, last_online_time)
@@ -16,7 +21,6 @@ export const setLastOnlineTime: APIHandler<'set-last-online-time'> = async (
1621
SET last_online_time = EXCLUDED.last_online_time
1722
WHERE user_activity.last_online_time < now() - interval '1 minute';
1823
`,
19-
[auth.uid]
24+
[userId]
2025
)
21-
// console.log('setLastOnline')
2226
}

web/hooks/use-online.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const useOnline = () => {
99
useEffect(() => {
1010
if (!profile || !isAuthed) return
1111
void (async () => {
12-
const date = new Date().toISOString()
12+
// const date = new Date().toISOString()
1313
// const result = await run(
1414
// db
1515
// .from('profiles')

0 commit comments

Comments
 (0)