Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Having issue with useSignIn hook with NextJS #162

Open
jsonpreet opened this issue Apr 22, 2024 · 2 comments
Open

Having issue with useSignIn hook with NextJS #162

jsonpreet opened this issue Apr 22, 2024 · 2 comments
Labels

Comments

@jsonpreet
Copy link

jsonpreet commented Apr 22, 2024

What is the bug?
I am trying useSignIn hook in NextJS 14.1.4, I logged In from Wrapcast app after Scanning QR code, but in return onSuccess event is not working. In console i am getting two things 1 is from farcaster relay and 2nd posting to blockchain.

image

How can it be reproduced? (optional)
https://github.com/jsonpreet/farcaster-login

@valentinludu
Copy link

valentinludu commented Jun 11, 2024

Had the exact same issue today. I managed to make it work by wrapping the methods in the useCallback hook.
For some reason the onSuccess/onError methods are not being triggered if they are not cached.

const onSuccessCallback = useCallback( (res: StatusAPIResponse) => { // Do something }, []);

const onErrorCallback = useCallback( (error?: AuthClientError) => { // Do something }, []);

const signInState = useSignIn({ onSuccess: onSuccessCallback, onError: onErrorCallback, });

@AmAzing129
Copy link

You might not be using 'useCallback' the way you intend to.

const onError = (error: any) => {
  console.log('error', error)
}

const onErrorCallback = useCallback(
  (error?: AuthClientError) => {
  onError?.(error)
}, [onError])

Considering onError will change every render, onErrorCallback will change too.

It's the same as onError: (error: any) => console.log('error', error)

In useSignIn, all the callback functions are dependencies. So it may cause the problem.

Maybe you can use the way the answer above mentioned to make the function unchanged during every rendering. It should be unchanged after all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants