-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Native email auth support * update sequence.js to snapshot release with native email auth * hacky solution to only use email auth v2 in dev mode
- Loading branch information
Showing
4 changed files
with
123 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { useState } from 'react' | ||
import { sequence } from '../main' | ||
|
||
|
||
export function useEmailAuthV2({ onSuccess, sessionName }: { onSuccess: (res: { wallet: string, sessionId: string }) => void, sessionName: string }) { | ||
const [email, setEmail] = useState("") | ||
const [error, setError] = useState<unknown>() | ||
const [loading, setLoading] = useState(false) | ||
const [instance, setInstance] = useState('') | ||
|
||
const initiateAuth = async (email: string) => { | ||
setLoading(true) | ||
|
||
try { | ||
const instance = await sequence.initiateEmailAuth(email) | ||
setInstance(instance!) | ||
setEmail(email) | ||
} catch (e: any) { | ||
console.error(e) | ||
setError(e.message || "Unknown error") | ||
} finally { | ||
setLoading(false) | ||
} | ||
} | ||
|
||
const sendChallengeAnswer = async (answer: string) => { | ||
setLoading(true) | ||
|
||
try { | ||
const res = await sequence.completeEmailAuth({ challenge: instance, answer, email, sessionName }) | ||
onSuccess(res) | ||
} catch (e: any) { | ||
setError(e.message || "Unknown error") | ||
} finally { | ||
setLoading(false) | ||
} | ||
} | ||
|
||
return { | ||
inProgress: loading || !!instance, | ||
loading, | ||
error, | ||
initiateAuth, | ||
sendChallengeAnswer: instance ? sendChallengeAnswer : undefined, | ||
} | ||
} |