Skip to content

Commit

Permalink
logs(mobile): add sentry logs to debug dev app
Browse files Browse the repository at this point in the history
  • Loading branch information
pchmn committed Aug 4, 2023
1 parent 531a2b7 commit ff7e631
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 10 additions & 0 deletions apps/mobile/src/core/auth/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { INSERT_KUZER, Kuzer } from '@kuzpot/core';
import { useInsertMutation } from '@kuzpot/react-native';
import { useAuthenticationStatus, useSignInAnonymous, useUserData } from '@nhost/react';
import { useCallback, useEffect, useState } from 'react';
import * as Sentry from 'sentry-expo';

import { useRegisterDevice } from './useRegisterDevice';

let isInit = false;

export function useAuth() {
Sentry.Native.captureMessage('useAuth');
const { register } = useRegisterDevice();

const { isAuthenticated, isLoading: authLoading } = useAuthenticationStatus();
Expand All @@ -19,21 +21,28 @@ export function useAuth() {

const initUser = useCallback(
async (userId: string) => {
Sentry.Native.setUser({ id: userId, role: 'anonymous' });
try {
await mutateUser({
id: userId,
status: 'online',
});
await register(userId);
Sentry.Native.captureMessage(`User ${userId} registered`);
setIsLoading(false);
} catch (err) {
Sentry.Native.captureException(err, { extra: { userId } });
console.error('nhost err', err);
setIsLoading(false);
}
},
[mutateUser, register]
);

useEffect(() => {
Sentry.Native.captureMessage(
`useAuth in useEffect: ${JSON.stringify({ authLoading, isAuthenticated, isInit }, null, 2)}}`
);
if (!authLoading && !isAuthenticated && !isInit) {
signInAnonymous()
.then((user) => {
Expand All @@ -42,6 +51,7 @@ export function useAuth() {
}
})
.catch((err) => {
Sentry.Native.captureException(err);
console.error('nhost err', err);
setIsLoading(false);
});
Expand Down
4 changes: 3 additions & 1 deletion apps/mobile/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ export default function Main() {
clientStorageType: 'react-native',
});
setIsReady(true);

Sentry.Native.captureMessage('Secure storage initialized');
})
.catch((err) => console.log('err', err));
.catch((err) => Sentry.Native.captureException(err));
}
}, []);

Expand Down

0 comments on commit ff7e631

Please sign in to comment.