Clean up comments

This commit is contained in:
Kyle Corbelli 2017-09-27 15:08:29 -07:00
parent 1bc7520928
commit 1c67ec2e3a
3 changed files with 5 additions and 26 deletions

View File

@ -1,9 +1,3 @@
// import { AsyncStorage } from 'react-native'
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Rip this out into its own npm package:
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const AsyncLocalStorage = { const AsyncLocalStorage = {
getItem: (key: string): Promise<any> => new Promise((resolve, reject) => { getItem: (key: string): Promise<any> => new Promise((resolve, reject) => {
try { try {
@ -72,8 +66,3 @@ const AsyncLocalStorage = {
} }
export default AsyncLocalStorage export default AsyncLocalStorage
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ^ Rip this out into its own npm package
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -40,11 +40,11 @@ import {
import AsyncLocalStorage from './AsyncLocalStorage' import AsyncLocalStorage from './AsyncLocalStorage'
import { import {
deleteAuthHeaders, deleteAuthHeaders,
deleteAuthHeadersFromLocalStorage, deleteAuthHeadersFromDeviceStorage,
getUserAttributesFromResponse, getUserAttributesFromResponse,
persistAuthHeadersInDeviceStorage, persistAuthHeadersInDeviceStorage,
setAuthHeaders, setAuthHeaders,
} from './services/auth' // <- maybe this is where you pass in the platform paramter, specifying if it is for a browser or for React Native } from './services/auth'
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Pure Redux actions: // Pure Redux actions:
@ -146,10 +146,9 @@ const generateAuthActions = (config: { [key: string]: any }): ActionsExport => {
data, data,
}) })
setAuthHeaders(response.headers) setAuthHeaders(response.headers)
// Have to check what type of platform it is, depending on the key provided by the end-user... like "browser", "iphone", or "android", etc.:
persistAuthHeadersInDeviceStorage(Storage, response.headers) persistAuthHeadersInDeviceStorage(Storage, response.headers)
const userAttributesToSave = getUserAttributesFromResponse(userAttributes, response) const userAttributesToSave = getUserAttributesFromResponse(userAttributes, response)
dispatch(registrationRequestSucceeded(userAttributesToSave)) // <- need to make this reducer more flexible dispatch(registrationRequestSucceeded(userAttributesToSave))
} catch (error) { } catch (error) {
dispatch(registrationRequestFailed()) dispatch(registrationRequestFailed())
throw error throw error
@ -167,7 +166,6 @@ const generateAuthActions = (config: { [key: string]: any }): ActionsExport => {
params: verificationParams, params: verificationParams,
}) })
setAuthHeaders(response.headers) setAuthHeaders(response.headers)
// Have to check what type of platform it is, depending on the key provided by the end-user... like "browser", "iphone", or "android", etc.:
persistAuthHeadersInDeviceStorage(Storage, response.headers) persistAuthHeadersInDeviceStorage(Storage, response.headers)
const userAttributesToSave = getUserAttributesFromResponse(userAttributes, response) const userAttributesToSave = getUserAttributesFromResponse(userAttributes, response)
dispatch(verifyTokenRequestSucceeded(userAttributesToSave)) dispatch(verifyTokenRequestSucceeded(userAttributesToSave))
@ -194,7 +192,6 @@ const generateAuthActions = (config: { [key: string]: any }): ActionsExport => {
}, },
}) })
setAuthHeaders(response.headers) setAuthHeaders(response.headers)
// Have to check what type of platform it is, depending on the key provided by the end-user... like "browser", "iphone", or "android", etc.:
persistAuthHeadersInDeviceStorage(Storage, response.headers) persistAuthHeadersInDeviceStorage(Storage, response.headers)
const userAttributesToSave = getUserAttributesFromResponse(userAttributes, response) const userAttributesToSave = getUserAttributesFromResponse(userAttributes, response)
dispatch(signInRequestSucceeded(userAttributesToSave)) dispatch(signInRequestSucceeded(userAttributesToSave))
@ -218,8 +215,7 @@ const generateAuthActions = (config: { [key: string]: any }): ActionsExport => {
data: userSignOutCredentials, data: userSignOutCredentials,
}) })
deleteAuthHeaders() deleteAuthHeaders()
// Have to check what type of platform it is, depending on the key provided by the end-user... like "browser", "iphone", or "android", etc.: deleteAuthHeadersFromDeviceStorage(Storage)
deleteAuthHeadersFromLocalStorage(Storage)
dispatch(signOutRequestSucceeded()) dispatch(signOutRequestSucceeded())
} catch (error) { } catch (error) {
dispatch(signOutRequestFailed()) dispatch(signOutRequestFailed())
@ -228,7 +224,6 @@ const generateAuthActions = (config: { [key: string]: any }): ActionsExport => {
} }
const verifyCredentials = async (store: Store<{}>): Promise<void> => { const verifyCredentials = async (store: Store<{}>): Promise<void> => {
// Gotta check what the platform is:
if (await Storage.getItem('access-token')) { if (await Storage.getItem('access-token')) {
const verificationParams: VerificationParams = { const verificationParams: VerificationParams = {
'access-token': await Storage.getItem('access-token') as string, 'access-token': await Storage.getItem('access-token') as string,

View File

@ -21,9 +21,7 @@ export const setAuthHeaders = (headers: AuthHeaders): void => {
}) })
} }
// Will have to take a parameter from the package user to determine if this is for a browser or for React Native:
export const persistAuthHeadersInDeviceStorage = (Storage: DeviceStorage, headers: AuthHeaders): void => { export const persistAuthHeadersInDeviceStorage = (Storage: DeviceStorage, headers: AuthHeaders): void => {
// use multiSet:
authHeaderKeys.forEach((key: string) => { authHeaderKeys.forEach((key: string) => {
Storage.setItem(key, headers[key]) Storage.setItem(key, headers[key])
}) })
@ -35,12 +33,9 @@ export const deleteAuthHeaders = (): void => {
}) })
} }
// Will have to take a parameter from the package user to determine if this is for a browser or for React Native: export const deleteAuthHeadersFromDeviceStorage = async (Storage: DeviceStorage): Promise<void> => {
export const deleteAuthHeadersFromLocalStorage = async (Storage: DeviceStorage): Promise<void> => {
// can use multiRemove once you've written it:
authHeaderKeys.forEach((key: string) => { authHeaderKeys.forEach((key: string) => {
Storage.removeItem(key) Storage.removeItem(key)
// localStorage.removeItem(key)
}) })
} }