-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf4f285
commit 47e04cf
Showing
18 changed files
with
957 additions
and
1,105 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
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
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
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,3 @@ | ||
export * from "./Auth"; | ||
export * from "./forIDP"; | ||
export * from "./useSocialOnboarding"; |
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,47 @@ | ||
import AsyncStorage from "@react-native-async-storage/async-storage"; | ||
import { type IDP } from "@umami/social-auth"; | ||
import { useAsyncActionHandler, useRestoreSocial } from "@umami/state"; | ||
import { getPublicKeyPairFromSk } from "@umami/tezos"; | ||
import { useRouter } from "expo-router"; | ||
|
||
import { forIDP } from "./forIDP"; | ||
import { persistor } from "../../store/store"; | ||
|
||
export const useSocialOnboarding = () => { | ||
const router = useRouter(); | ||
const restoreSocial = useRestoreSocial(); | ||
const { handleAsyncAction } = useAsyncActionHandler(); | ||
|
||
const login = (idp: IDP) => | ||
handleAsyncAction(async () => { | ||
const { secretKey, name, id, email } = await forIDP(idp).getCredentials(); | ||
const { pk, pkh } = await getPublicKeyPairFromSk(secretKey); | ||
restoreSocial(pk, pkh, email || name || id, idp); | ||
router.replace("/home"); | ||
}); | ||
|
||
const logout = (idp: IDP) => | ||
handleAsyncAction(async () => { | ||
await forIDP(idp).logout(); | ||
persistor.pause(); | ||
await AsyncStorage.clear(); | ||
router.replace("/onboarding"); | ||
}); | ||
|
||
const createLoginHandler = (provider: IDP) => () => login(provider); | ||
|
||
const onGoogleLogin = createLoginHandler("google"); | ||
const onFacebookLogin = createLoginHandler("facebook"); | ||
const onXLogin = createLoginHandler("twitter"); | ||
const onRedditLogin = createLoginHandler("reddit"); | ||
const onAppleLogin = createLoginHandler("apple"); | ||
|
||
return { | ||
onGoogleLogin, | ||
onFacebookLogin, | ||
onXLogin, | ||
onRedditLogin, | ||
onAppleLogin, | ||
logout, | ||
}; | ||
}; |
Oops, something went wrong.
47e04cf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.