-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(notifications): generating and moving clientId to preferences
- Loading branch information
1 parent
3ac5546
commit 5e52fbb
Showing
7 changed files
with
93 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import 'react-native-get-random-values'; | ||
import * as Keychain from 'react-native-keychain'; | ||
|
||
import { v4 as uuidv4 } from 'uuid'; | ||
|
||
import { PreferencesContextProps } from '../../contexts/PreferencesContext'; | ||
|
||
export const migrateClientIdToPreferences = async ( | ||
preferences: PreferencesContextProps, | ||
) => { | ||
const { updatePreference } = preferences; | ||
try { | ||
const credentials = await Keychain.getGenericPassword(); | ||
let clientId; | ||
if (credentials && credentials.username) { | ||
clientId = credentials.username; | ||
} else { | ||
clientId = uuidv4(); | ||
} | ||
updatePreference('clientId', clientId); | ||
} catch (e) { | ||
console.warn( | ||
"Keychain couldn't be accessed! Failed to migrate clientId.", | ||
e, | ||
); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters