Skip to content

Commit

Permalink
Merge pull request #903 from near/handle-pending-vm-fastauth-events
Browse files Browse the repository at this point in the history
feat: trigger events if redirect search params are present
  • Loading branch information
esaminu authored Jan 4, 2024
2 parents 1d5b5af + 6e0f244 commit 83197dd
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/pages/signin.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { getKeys, isPassKeyAvailable } from '@near-js/biometric-ed25519';
import { useRouter } from 'next/router';
import { useSearchParams } from 'next/navigation';
import { useEffect } from 'react';
import { useForm } from 'react-hook-form';
import styled from 'styled-components';

import { Button } from '@/components/lib/Button';
import { openToast } from '@/components/lib/Toast';
import { useClearCurrentComponent } from '@/hooks/useClearCurrentComponent';
import { useDefaultLayout } from '@/hooks/useLayout';
import { useSignInRedirect } from '@/hooks/useSignInRedirect';
Expand All @@ -17,10 +15,10 @@ import { isValidEmail } from '../utils/form-validation';

const SignInPage: NextPageWithLayout = () => {
const { register, handleSubmit, setValue } = useForm();
const router = useRouter();
const requestSignInWithWallet = useAuthStore((store) => store.requestSignInWithWallet);
const signedIn = useAuthStore((store) => store.signedIn);
const vmNear = useAuthStore((store) => store.vmNear);
const searchParams = useSearchParams();
const { redirect } = useSignInRedirect();

useEffect(() => {
Expand All @@ -29,6 +27,18 @@ const SignInPage: NextPageWithLayout = () => {
}
}, [redirect, signedIn]);

useEffect(() => {
if (vmNear?.selector && searchParams.get('account_id') && searchParams.get('public_key')) {
vmNear.selector
.then((selector: any) => selector.wallet('fast-auth-wallet'))
.then((fastAuthWallet: any) =>
fastAuthWallet.signIn({
contractId: vmNear.config.contractName,
}),
);
}
}, [searchParams, vmNear]);

useClearCurrentComponent();

const onSubmit = handleSubmit(async (data) => {
Expand Down

0 comments on commit 83197dd

Please sign in to comment.