Skip to content

Commit

Permalink
sign api requests and include in query vars for authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
kibagateaux committed Dec 10, 2023
1 parent 970d59b commit e64f040
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 8 deletions.
118 changes: 118 additions & 0 deletions app.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
const isProd = process.env.EXPO_PUBLIC_APP_VARIANT === 'production';

const packageName = isProd ? 'com.jinnihealth' : `com.jinnihealth.${VARIANT}`;
const appName = isProd ? 'Jinni Health' : `Jinni Health (${VARIANT})`;
export default {
expo: {
name: appName,
slug: 'jinni-health',
version: '0.0.1',
orientation: 'portrait',
icon: './public/icon.png',
userInterfaceStyle: 'light',
splash: {
image: './public/splash.png',
resizeMode: 'contain',
backgroundColor: '#ffffff',
},
assetBundlePatterns: ['**/*'],
scheme: 'jinni-health',
plugins: [
'react-native-health',
'react-native-health-connect',
'react-native-nfc-manager',
[
'expo-build-properties',
{
ios: {
deploymentTarget: '16.0',
},
android: {
compileSdkVersion: 34,
targetSdkVersion: 34,
minSdkVersion: 26,
},
},
],
[
'expo-contacts',
{
contactsPermission:
'Allow your jinni to access your friends list to contact their jinn and communicate with them in the spiritual world.',
},
],
[
'expo-location',
{
locationAlwaysAndWhenInUsePermission:
'Allow your jinni to follow you and protect you around the world.',
isAndroidBackgroundLocationEnabled: false,
},
],
'expo-router',
'sentry-expo',
],
hooks: {
postPublish: [
{
file: 'sentry-expo/upload-sourcemaps',
config: {
organization: '${EXPO_PUBLIC_SENTRY_ORG}',
project: '${EXPO_PUBLIC_SENTRY_PROJECT}',
},
},
],
},
ios: {
supportsTablet: false,
infoPlist: {
NSContactsUsageDescription:
'Allow your jinni to access your friends list to contact their jinn and communicate with them in the spiritual world.',
},
bundleIdentifier: packageName,
},
android: {
adaptiveIcon: {
foregroundImage: './public/adaptive-icon.png',
backgroundColor: '#ffffff',
},
permissions: [
'android.permission.NFC',
'android.permission.READ_CONTACTS',
'android.permission.WRITE_CONTACTS',
'android.permission.health.READ_STEPS',
'android.permission.health.READ_ACTIVE_CALORIES_BURNED',
'android.permission.health.READ_TOTAL_CALORIES_BURNED',
'android.permission.health.READ_BASAL_METABOLIC_RATE',
'android.permission.health.READ_LEAN_BODY_MASS',
'android.permission.health.READ_BODY_FAT',
'android.permission.health.READ_EXERCISE',
'android.permission.health.READ_DISTANCE',
'android.permission.health.READ_HEART_RATE',
'android.permission.health.READ_NUTRITION',
'android.permission.health.READ_HYDRATION',
'android.permission.health.READ_RESPIRATORY_RATE',
'android.permission.health.READ_RESTING_HEART_RATE',
'android.permission.health.READ_SLEEP',
'android.permission.health.READ_WEIGHT',
'android.permission.ACCESS_COARSE_LOCATION',
'android.permission.ACCESS_FINE_LOCATION',
'android.permission.FOREGROUND_SERVICE',
],
package: packageName,
},
experiments: {
typedRoutes: true,
tsconfigPaths: true,
},
extra: {
router: {
origin: false,
},
eas: {
projectId: '9d90a8bf-a538-49f0-925c-afd83fd4c8d3',
},
},
owner: 'malik2',
},
};
3 changes: 2 additions & 1 deletion src/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ const HomeScreen = () => {
const onIntentionPress = async () => {
const now = new Date();
const oneDayAgo = new Date(now.getTime() - 24 * 60 * 60 * 1000);
const startTime = oneDayAgo.toISOString();
const startTime = oneDayAgo.toISOString(); // TODO last activity time
const endTime = now.toISOString();
await getActivityData({ startTime, endTime });
};

return (
<View style={{ flex: 1, ...useTheme() }}>
<View style={styles.container}>
Expand Down
2 changes: 1 addition & 1 deletion src/types/UserConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export type GameWidgetIds =
| 'stat-stength'
| 'stat-stamina'
| 'stat-spirit';
// player action portals

// player action portals
export type ItemWidgetIds =
| 'maliks-majik-leaderboard'
// identity
Expand Down
37 changes: 31 additions & 6 deletions src/utils/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
import { getAppConfig } from './config';
import { getSpellBook } from './zkpid';

// TODO persist cache to local storage for better offline use once internet connection lost?
// https://www.apollographql.com/docs/react/caching/advanced-topics#persisting-the-cache
Expand All @@ -17,22 +18,28 @@ export const getGqlClient = () =>
version: '0.0.1',
}));

export const qu = (query: string) => (variables: object) =>
// strip /n and /t to prevent weird error converting to byte array on server side on ecrecvoer
export const qu = (query: string) => async (variables: object) =>
getGqlClient().query({
// strip /n and /t to prevent weird error converting to byte array on server side on ecrecvoer
query: gql`
${query.replace(/[\n\t]/g, ' ')}
`,
variables,
variables: {
...variables,
verification: (await getSpellBook()).signMessage(query),
},
fetchPolicy: 'cache-first', // TODO add useCache: boolean to switch between query vs readQuery?
});

export const mu = (mutation: string) => (variables: object) =>
export const mu = (mutation: string) => async (variables: object) =>
getGqlClient().mutate({
mutation: gql`
${mutation}
${mutation.replace(/[\n\t]/g, ' ')}
`,
variables,
variables: {
...variables,
verification: (await getSpellBook()).signMessage(mutation),
},

optimisticResponse: true,
});
Expand All @@ -52,3 +59,21 @@ export const MU_ACTIVATE_JINNI = `
}
}
`;

export const MU_SUBMIT_DATA = `
mutation submit_data(
$verification: SignedRequest!
$data: [RawInputData]!
$data_provider: DataProvider!
$name: String!
) {
submit_data(
verification: $verification,
data: $data
data_provider: $data_provider
name: $name
) {
ID
}
}
`;

0 comments on commit e64f040

Please sign in to comment.