DEV Community

loading...

Discussion on: GraphQL Auth with Passport and Lighthouse PHP

Collapse
ramirezfer772 profile image
ramirezfer772

Encontre una solución para verificar el email, la dejo aquí por si le sirve a alguien en el futuro:
1.crear un mutation VerifyEMail.php con este codigo:
public function __invoke($rootValue, array $args, GraphQLContext $context, ResolveInfo $resolveInfo)
{

    $email = $args['email'];
    $requestHash = $args['requestHash'];
    $requestID = $args['requestID'];

    $user = User::where('email', $email)->first();

    if (! hash_equals((string) $requestID, (string) $user->getKey())) {
        throw new AuthorizationException;
    }

    if (! hash_equals((string) $requestHash, sha1($user->getEmailForVerification()))) {
        throw new AuthorizationException;
    }

    if ($user->markEmailAsVerified()) {
        event(new Verified($user));

        return $user;
    }

}

2.testear:
mutation {
VerifyEMail(
email:"example@gmail.com"
requestID: 10
requestHash: "b2cce7e16059b006a97cb2a2e2fcde1cafeb7bc5"
) {
id
}
}

  1. en web.php:

Route::get('email/verify/{id}/{hash}', function () {
return view('welcome');
})->name('verification.verify')

4.desde la vista mandar el email que el usuario escribió, mandar la id y el hash

Ojala sirva.