@@ -18,9 +18,10 @@ interface IAtlasProvider {
1818
1919const Context = createContext < IAtlasProvider | undefined > ( undefined ) ;
2020
21- // eslint-disable-next-line
22- // @ts -ignore
23- const atlasUri = import . meta. env . REACT_APP_ATLAS_URI ?? "" ;
21+ const atlasUri : string = import . meta. env . REACT_APP_ATLAS_URI ?? "" ;
22+ if ( ! atlasUri ) {
23+ console . warn ( "REACT_APP_ATLAS_URI is not defined. Please check your environment variables." ) ;
24+ }
2425
2526const AtlasProvider : React . FC < { children ?: React . ReactNode } > = ( { children } ) => {
2627 const { address } = useAccount ( ) ;
@@ -75,27 +76,24 @@ const AtlasProvider: React.FC<{ children?: React.ReactNode }> = ({ children }) =
7576 /**
7677 * @description authorise user and enable authorised calls
7778 */
78- const authoriseUser = useCallback ( ( ) => {
79- if ( ! address ) return ;
80- setIsSigningIn ( true ) ;
81- getNonce ( atlasGqlClient , address )
82- . then ( ( nonce ) => {
83- const message = createMessage ( address , chainId , nonce ) ;
84- signMessageAsync ( { message } ) . then ( ( signature ) => {
85- if ( ! isUndefined ( signature ) ) {
86- loginUser ( atlasGqlClient , { signature, message } )
87- . then ( ( token ) => {
88- setAuthToken ( token ) ;
89- } )
90- . finally ( ( ) => setIsSigningIn ( false ) ) ;
91- }
92- } ) ;
93- } )
94- . catch ( ( err ) => {
95- // eslint-disable-next-line no-console
96- console . log ( `authorise user error : ${ err ?. message } ` ) ;
97- setIsSigningIn ( false ) ;
98- } ) ;
79+ const authoriseUser = useCallback ( async ( ) => {
80+ try {
81+ if ( ! address || ! chainId ) return ;
82+ setIsSigningIn ( true ) ;
83+ const nonce = await getNonce ( atlasGqlClient , address ) ;
84+ const message = createMessage ( address , nonce , chainId ) ;
85+ const signature = await signMessageAsync ( { message } ) ;
86+
87+ if ( ! signature ) return ;
88+ const token = await loginUser ( atlasGqlClient , { message, signature } ) ;
89+
90+ setAuthToken ( token ) ;
91+ } catch ( err : any ) {
92+ // eslint-disable-next-line
93+ console . log ( "Authorize User Error : " , err ?. message ) ;
94+ } finally {
95+ setIsSigningIn ( false ) ;
96+ }
9997 } , [ address , chainId , setAuthToken , signMessageAsync , atlasGqlClient ] ) ;
10098
10199 return (
0 commit comments