RyanDaDeng / laravel-google-recaptcha-v3

It's probably the best Laravel Package for Google reCAPTCHA v3. Vue component supported.
MIT License
273 stars 40 forks source link

Unable to use properly with Vue #81

Closed w99910 closed 1 year ago

w99910 commented 3 years ago

After submitting the form in vue, the page is returned as domain.com/?g-recaptcha-response=XXXXXXXXXX and doesn't continue the process. I'm implementing the recaptcha in vue login request and the code in my component is the following. It doesn't return none of error. Can someone help me please?

config/googlerecaptchav3.php

'setting' => [
        [
            'action' => 'action',
            'threshold' => 0.2,
            'score_comparision' => false,
        ],

Template

 <google-re-captcha-v3
            v-model="gRecaptchaResponse"
            ref="captcha"
            :site-key="mySiteKeyVariable"
            action="action"
            id="action_id"
        ></google-re-captcha-v3>

method

axios.post('/login',{recaptcha:this.gRecaptchaResponse,_token:csrf,email:this.email,password:this.password,remember:this.remember}).then((res)=>{                this.loading=false;
                        this.toast(res.data.location,1);
                       this.$refs.captcha.execute();
                   }).catch((error)=>{
                        this.Error=error.response.data.message;
                        this.loading=false;
                        this.toast();
                        this.$refs.captcha.execute();
                    });

Controller

$rules = [
            'recaptcha' => [new GoogleReCaptchaV3ValidationRule('frontier_action')],
            'email'=>'required|email',
            'password'=>'required',
        ];
        info($request->all());
        $validator = \Illuminate\Support\Facades\Validator::make($request->only('email','password','recaptcha'),$rules);
        if($validator->fails()){
            return response()->json(['errors'=>$validator->errors()],400);
        }
$route=route('home');
         return response()->json(['message' => 'Successfully Login', 'location' => $route], 200);
w99910 commented 3 years ago

info(GoogleReCaptchaV3::verifyResponse($request['gRecaptchaResponse'])->isSuccess()) gives 1 and info(GoogleReCaptchaV3::verifyResponse($request['gRecaptchaResponse'])->getMessage()) gives 'The action is timeout.'.

RyanDaDeng commented 3 years ago

make 'is_score_enabled' => true, and also enable your action 'score_comparision' => false, to be true