-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
126 lines (104 loc) · 3.83 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/**
* //@//format
*/
import React from 'react';
//import { Rehydrated } from 'aws-appsync-react';
import Rehydrated from './src/util/rehydrated/Rehydrated';
import { registerRootComponent } from 'expo';
import AWSAppSyncClient, {AUTH_TYPE} from 'aws-appsync';
import { Auth, Amplify } from 'aws-amplify';
import AppSyncConfig from './aws-exports';
import App from './App';
import { ApolloProvider } from '@apollo/client';
import InAppBrowser from 'react-native-inappbrowser-reborn';
import * as Linking from 'expo-linking';
async function urlOpener (url, redirectUrl) {
const brow = await InAppBrowser.isAvailable();
try {
if (brow) {
InAppBrowser.openAuth(url, redirectUrl, {
showTitle: false,
enableUrlBarHiding: true,
enableDefaultShare: false,
ephemeralWebSession: false,
forceCloseOnRedirection: true,
hasBackButton: true,
}).then((response) => {
if (
response.type === 'success' &&
response.url
) {
Linking.openURL(response.url)
}
})
} else Linking.openURL(url)
} catch (error) {
Linking.openURL(url)
}
};
const oauth = {
// Domain name //********.auth.us-east-1.amazoncognito.com
domain : 'xxxx1111-xxxx-chatic.auth.us-east-1.amazoncognito.com',
// Authorized scopes
scope : ['phone', 'email', 'profile', 'openid','aws.cognito.signin.user.admin'],
// Callback URL
redirectSignIn : 'chforum://', // http://www.example.com/signin/ or 'exp://127.0.0.1:19000/--/', 'myapp://main/'
// Sign out URL
redirectSignOut : 'chforum://', // 'http://www.example.com/signout/' or 'exp://127.0.0.1:19000/--/', 'myapp://main/'
// 'code' for Authorization code grant,
// 'token' for Implicit grant
// Note that REFRESH token will only be generated when the responseType is code
responseType: 'code',
// optional, for Cognito hosted ui specified options
options: {
// Indicates if the data collection is enabled to support Cognito advanced security features. By default, this flag is set to true.
AdvancedSecurityDataCollectionFlag : true
},
urlOpener
}
AppSyncConfig.oauth = oauth;
Amplify.configure(AppSyncConfig);
const options = {
defaultOptions: {
watchQuery: {
fetchPolicy: 'cache-and-network',
}
}
}
const clientpublic = new AWSAppSyncClient({
url: AppSyncConfig.aws_appsync_graphqlEndpoint,
region: AppSyncConfig.aws_appsync_region,
auth: {
type: AUTH_TYPE.API_KEY, apiKey: AppSyncConfig.aws_appsync_apiKey,
//type: AppSyncConfig.aws_appsync_authenticationType,
jwtToken: async () => (await Auth.currentSession()).idToken.jwtToken
},offlineConfig: {
keyPrefix: 'getinitialpublic'},options
});
//const querysubs = clientpublic.watchQuery().subscribe
const clientprivate = new AWSAppSyncClient({
url: AppSyncConfig.aws_appsync_graphqlEndpoint,
region: AppSyncConfig.aws_appsync_region,
auth: {
type: AppSyncConfig.aws_appsync_authenticationType,
jwtToken: async () => (await Auth.currentSession()).idToken.jwtToken
},offlineConfig: {
keyPrefix: 'getinitialprivate'}
},options
);
//const RehydratedWithClient = withApollo(Rehydrated);
const AppWithProvider = () => (
<ApolloProvider client={{clientpublic, clientprivate}}>
<Rehydrated>
<App />
</Rehydrated>
</ApolloProvider>
);
// registerRootComponent calls AppRegistry.registerComponent('main', () => App);
// It also ensures that whether you load the app in the Expo client or in a native build,
// the environment is set up appropriately
registerRootComponent(AppWithProvider);
/*import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
AppRegistry.registerComponent('main', () => App);*/