Skip to content

Instantly share code, notes, and snippets.

@dmennis
Created May 30, 2019 22:51
Show Gist options
  • Save dmennis/b7b7735da0c138b0eb352a7cbc053ad4 to your computer and use it in GitHub Desktop.
Save dmennis/b7b7735da0c138b0eb352a7cbc053ad4 to your computer and use it in GitHub Desktop.
iOS AppSync Multi Auth - API_KEY
// WITH multi-auth
func initializeAppSync_API_Key() {
do {
// Reference the API_KEY auth mode setting in awsconfiguration.json
let serviceConfigAPI_Key = try AWSAppSyncServiceConfig(forKey: "recipedemo_API_KEY")
// useClientDatabasePrefix: true is telling the AppSync client to look for 'ClientDatabasePrefix' in awsconfiguration.json
// why the cacheConfig? AppSync client uses a unique cache database for each auth type
let cacheConfig = try AWSAppSyncCacheConfiguration(useClientDatabasePrefix: true,
appSyncServiceConfig: serviceConfigAPI_Key)
// Initialize the AWS AppSync configuration to reference the "recipedemo_API_KEY" auth mode in awsconfiguration.json
let appSyncConfig = try AWSAppSyncClientConfiguration(appSyncServiceConfig: serviceConfigAPI_Key, cacheConfiguration: cacheConfig)
// Initialize the AWS AppSync client
appSyncClient = try AWSAppSyncClient(appSyncConfig: appSyncConfig)
} catch {
print("Error initializing appsync client. \(error)")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment