fingerprintjs / fingerprintjs-pro-react

Fingerprint Pro Wrapper for React Single Page Applications (SPA)
MIT License
52 stars 8 forks source link

Allow `getData` to throw errors, allow multiple failed requests, error messages doesn't match library constants #70

Closed inrumi closed 1 year ago

inrumi commented 2 years ago

Hello I've been getting some Client timeout validations for some users that try to log in from a mobile with low signal where in those cases I've setted up fallback to other types of security validations the problem is that the only way to handle those errors is from the error coming from useVisitorData I want to be able to handle those errors on a try/catch clause using getData instead.

Another issue that I've found is that the errors defined in @fingerprintjs/fingerprintjs-pro do not match exactly the errors coming from the API

import { ERROR_CLIENT_TIMEOUT } from '@fingerprintjs/fingerprintjs-pro';

The error message that is returned from the your service has this Error: prefixed on every error so its not possble to handle those errors like you mention in your documentation

ERROR_CLIENT_TIMEOUT !== "Error: Clear timeout"

Finally for my use case where I use getData when the user tries to log in once I get an invalid response it won't let me fetch another response unless I unmount the hook or refresh the page, I should be able to use getData and get responses from it on demand, not only once per component mounted.

Here is an screencast of the issue:

https://user-images.githubusercontent.com/18445985/198707059-fca05c66-7170-4e9f-a891-b1b6e249f827.mov

TheUnderScorer commented 2 years ago

Hey @inrumi!

Thanks for creating this issue, let me reply to specific points:

Hello I've been getting some Client timeout validations for some users that try to log in from a mobile with low signal where in those cases I've setted up fallback to other types of security validations the problem is that the only way to handle those errors is from the error coming from useVisitorData I want to be able to handle those errors on a try/catch clause using getData instead.

It makes sense to me, but we'll need to discuss this internally to decide how it will be implemented.

The error message that is returned from the your service has this Error: prefixed on every error so its not possble to handle those errors like you mention in your documentation

It looks like a bug to me, I'll investigate it.

Finally for my use case where I use getData when the user tries to log in once I get an invalid response it won't let me fetch another response unless I unmount the hook or refresh the page, I should be able to use getData and get responses from it on demand, not only once per component mounted.

Have you tried playing with our cache API? You can try to clear the cache in cases when you want to fetch fresh data:

import { useContext } from 'react'
import FpjsContext from './fpjs-context'

const { clearCache } = useContext(FpjsContext)

clearCache()

You can also pass ignoreCache flag into getData method:


const {getData} = useVisitorData()

getData({ignoreCache: true})
inrumi commented 2 years ago

Hello & thanks for you reply, I'm happy to see that the error strings are now fixed, thank you!.

About the last 2 questions I tried both of them on the SPA example in this repository and yeah still didn't work in both ways. set it up like this:

import { useContext, useState } from 'react'
import { FpjsContext, useVisitorData } from '@fingerprintjs/fingerprintjs-pro-react'
...
  const { clearCache } = useContext(FpjsContext)

  const { getData } = useVisitorData(
    { extendedResult, tag, linkedId: login, timeout: 1 },
    { immediate: false }
  )

  return (
    <section className='body'>
      <form
        className='form'
        onSubmit={(e) => {
          e.preventDefault()
          getData({ ignoreCache }).then((data) => {
            clearCache();
            if (data) {
              // do something with the visitor data
              // for example, append visitor data to the form data to send to your server
              console.log(data)
            }
          })
        }}
      >
...
TheUnderScorer commented 2 years ago

Hey,

thanks for providing more details! After some investigating, it seems that the issue might come from our JavaScript Agent, but we'll need to check it thoroughly first.

Meanwhile, the feature with throwing errors when calling getData will be released soon 😉.

ilfa commented 1 year ago

:tada: This issue has been resolved in version 2.1.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

TheUnderScorer commented 1 year ago

Hey @inrumi,

the issue should be fixed now. Turns out it was caused by the cache layer in our SPA library dependency.

inrumi commented 1 year ago

Thanks a lot for all the fixes! I'm gonna to update my dependencies and check them out, seriously thanks a lot!