Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
e7608eeb
Commit
e7608eeb
authored
Jan 17, 2025
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pass ReCaptcha token to API request when signing in with wallet
parent
24bdfda8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
7 deletions
+28
-7
useReCaptcha.tsx
ui/shared/reCaptcha/useReCaptcha.tsx
+2
-2
AuthModalScreenConnectWallet.tsx
ui/snippets/auth/screens/AuthModalScreenConnectWallet.tsx
+16
-2
useSignInWithWallet.ts
ui/snippets/auth/useSignInWithWallet.ts
+10
-3
No files found.
ui/shared/reCaptcha/useReCaptcha.tsx
View file @
e7608eeb
...
@@ -7,10 +7,10 @@ export default function useReCaptcha() {
...
@@ -7,10 +7,10 @@ export default function useReCaptcha() {
const
[
isOpen
,
setIsOpen
]
=
React
.
useState
(
false
);
const
[
isOpen
,
setIsOpen
]
=
React
.
useState
(
false
);
const
executeAsync
=
React
.
useCallback
(
async
()
=>
{
const
executeAsync
:
()
=>
Promise
<
string
|
null
>
=
React
.
useCallback
(
async
()
=>
{
setIsOpen
(
true
);
setIsOpen
(
true
);
const
tokenPromise
=
ref
.
current
?.
executeAsync
()
||
Promise
.
reject
(
new
Error
(
'
Unable to execute ReCaptcha
'
));
const
tokenPromise
=
ref
.
current
?.
executeAsync
()
||
Promise
.
reject
(
new
Error
(
'
Unable to execute ReCaptcha
'
));
const
modalOpenPromise
=
new
Promise
<
void
>
((
resolve
,
reject
)
=>
{
const
modalOpenPromise
=
new
Promise
<
null
>
((
resolve
,
reject
)
=>
{
rejectCb
.
current
=
reject
;
rejectCb
.
current
=
reject
;
});
});
...
...
ui/snippets/auth/screens/AuthModalScreenConnectWallet.tsx
View file @
e7608eeb
...
@@ -5,6 +5,8 @@ import type { ScreenSuccess } from '../types';
...
@@ -5,6 +5,8 @@ import type { ScreenSuccess } from '../types';
import
type
{
UserInfo
}
from
'
types/api/account
'
;
import
type
{
UserInfo
}
from
'
types/api/account
'
;
import
type
*
as
mixpanel
from
'
lib/mixpanel
'
;
import
type
*
as
mixpanel
from
'
lib/mixpanel
'
;
import
ReCaptcha
from
'
ui/shared/reCaptcha/ReCaptcha
'
;
import
useReCaptcha
from
'
ui/shared/reCaptcha/useReCaptcha
'
;
import
useSignInWithWallet
from
'
../useSignInWithWallet
'
;
import
useSignInWithWallet
from
'
../useSignInWithWallet
'
;
...
@@ -17,6 +19,7 @@ interface Props {
...
@@ -17,6 +19,7 @@ interface Props {
const
AuthModalScreenConnectWallet
=
({
onSuccess
,
onError
,
isAuth
,
source
}:
Props
)
=>
{
const
AuthModalScreenConnectWallet
=
({
onSuccess
,
onError
,
isAuth
,
source
}:
Props
)
=>
{
const
isStartedRef
=
React
.
useRef
(
false
);
const
isStartedRef
=
React
.
useRef
(
false
);
const
recaptcha
=
useReCaptcha
();
const
handleSignInSuccess
=
React
.
useCallback
(({
address
,
profile
}:
{
address
:
string
;
profile
:
UserInfo
})
=>
{
const
handleSignInSuccess
=
React
.
useCallback
(({
address
,
profile
}:
{
address
:
string
;
profile
:
UserInfo
})
=>
{
onSuccess
({
type
:
'
success_wallet
'
,
address
,
isAuth
,
profile
});
onSuccess
({
type
:
'
success_wallet
'
,
address
,
isAuth
,
profile
});
...
@@ -26,7 +29,13 @@ const AuthModalScreenConnectWallet = ({ onSuccess, onError, isAuth, source }: Pr
...
@@ -26,7 +29,13 @@ const AuthModalScreenConnectWallet = ({ onSuccess, onError, isAuth, source }: Pr
onError
(
isAuth
);
onError
(
isAuth
);
},
[
onError
,
isAuth
]);
},
[
onError
,
isAuth
]);
const
{
start
}
=
useSignInWithWallet
({
onSuccess
:
handleSignInSuccess
,
onError
:
handleSignInError
,
source
,
isAuth
});
const
{
start
}
=
useSignInWithWallet
({
onSuccess
:
handleSignInSuccess
,
onError
:
handleSignInError
,
source
,
isAuth
,
executeRecaptchaAsync
:
recaptcha
.
executeAsync
,
});
React
.
useEffect
(()
=>
{
React
.
useEffect
(()
=>
{
if
(
!
isStartedRef
.
current
)
{
if
(
!
isStartedRef
.
current
)
{
...
@@ -35,7 +44,12 @@ const AuthModalScreenConnectWallet = ({ onSuccess, onError, isAuth, source }: Pr
...
@@ -35,7 +44,12 @@ const AuthModalScreenConnectWallet = ({ onSuccess, onError, isAuth, source }: Pr
}
}
},
[
start
]);
},
[
start
]);
return
<
Center
h=
"100px"
><
Spinner
/></
Center
>;
return
(
<
Center
h=
"100px"
>
<
Spinner
/>
<
ReCaptcha
ref=
{
recaptcha
.
ref
}
/>
</
Center
>
);
};
};
export
default
React
.
memo
(
AuthModalScreenConnectWallet
);
export
default
React
.
memo
(
AuthModalScreenConnectWallet
);
ui/snippets/auth/useSignInWithWallet.ts
View file @
e7608eeb
...
@@ -17,9 +17,10 @@ interface Props {
...
@@ -17,9 +17,10 @@ interface Props {
onError
?:
()
=>
void
;
onError
?:
()
=>
void
;
source
?:
mixpanel
.
EventPayload
<
mixpanel
.
EventTypes
.
WALLET_CONNECT
>
[
'
Source
'
];
source
?:
mixpanel
.
EventPayload
<
mixpanel
.
EventTypes
.
WALLET_CONNECT
>
[
'
Source
'
];
isAuth
?:
boolean
;
isAuth
?:
boolean
;
executeRecaptchaAsync
:
()
=>
Promise
<
string
|
null
>
;
}
}
function
useSignInWithWallet
({
onSuccess
,
onError
,
source
=
'
Login
'
,
isAuth
}:
Props
)
{
function
useSignInWithWallet
({
onSuccess
,
onError
,
source
=
'
Login
'
,
isAuth
,
executeRecaptchaAsync
}:
Props
)
{
const
[
isPending
,
setIsPending
]
=
React
.
useState
(
false
);
const
[
isPending
,
setIsPending
]
=
React
.
useState
(
false
);
const
isConnectingWalletRef
=
React
.
useRef
(
false
);
const
isConnectingWalletRef
=
React
.
useRef
(
false
);
...
@@ -32,11 +33,17 @@ function useSignInWithWallet({ onSuccess, onError, source = 'Login', isAuth }: P
...
@@ -32,11 +33,17 @@ function useSignInWithWallet({ onSuccess, onError, source = 'Login', isAuth }: P
try
{
try
{
const
siweMessage
=
await
apiFetch
(
'
auth_siwe_message
'
,
{
queryParams
:
{
address
}
})
as
{
siwe_message
:
string
};
const
siweMessage
=
await
apiFetch
(
'
auth_siwe_message
'
,
{
queryParams
:
{
address
}
})
as
{
siwe_message
:
string
};
const
signature
=
await
signMessageAsync
({
message
:
siweMessage
.
siwe_message
});
const
signature
=
await
signMessageAsync
({
message
:
siweMessage
.
siwe_message
});
const
recaptchaToken
=
await
executeRecaptchaAsync
();
if
(
!
recaptchaToken
)
{
throw
new
Error
(
'
ReCaptcha is not solved
'
);
}
const
resource
=
isAuth
?
'
auth_link_address
'
:
'
auth_siwe_verify
'
;
const
resource
=
isAuth
?
'
auth_link_address
'
:
'
auth_siwe_verify
'
;
const
response
=
await
apiFetch
<
typeof
resource
,
UserInfo
,
unknown
>
(
resource
,
{
const
response
=
await
apiFetch
<
typeof
resource
,
UserInfo
,
unknown
>
(
resource
,
{
fetchParams
:
{
fetchParams
:
{
method
:
'
POST
'
,
method
:
'
POST
'
,
body
:
{
message
:
siweMessage
.
siwe_message
,
signature
},
body
:
{
message
:
siweMessage
.
siwe_message
,
signature
,
recaptcha_response
:
recaptchaToken
},
},
},
});
});
if
(
!
(
'
name
'
in
response
))
{
if
(
!
(
'
name
'
in
response
))
{
...
@@ -56,7 +63,7 @@ function useSignInWithWallet({ onSuccess, onError, source = 'Login', isAuth }: P
...
@@ -56,7 +63,7 @@ function useSignInWithWallet({ onSuccess, onError, source = 'Login', isAuth }: P
}
finally
{
}
finally
{
setIsPending
(
false
);
setIsPending
(
false
);
}
}
},
[
apiFetch
,
isAuth
,
onError
,
onSuccess
,
signMessageAsync
,
toast
]);
},
[
apiFetch
,
isAuth
,
onError
,
onSuccess
,
signMessageAsync
,
toast
,
executeRecaptchaAsync
]);
const
start
=
React
.
useCallback
(()
=>
{
const
start
=
React
.
useCallback
(()
=>
{
setIsPending
(
true
);
setIsPending
(
true
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment