refine icon indicating copy to clipboard operation
refine copied to clipboard

[FEAT] `useVerify` hook

Open MahirMahdi opened this issue 2 years ago • 8 comments

Is your feature request related to a problem? Please describe.

Just a suggestion, how about adding a useVerify hook into the Core API's Authentication?

Describe alternatives you've considered

No response

Additional context

No response

Describe the thing to improve

It would be great to have a useVerify hook for email verification purposes just like there are hooks like useLogin for logging in and useUpdatePassword for updating passwords.

MahirMahdi avatar Aug 17 '23 00:08 MahirMahdi

Hello @MahirMahdi, We appreciate your suggestion.

Could you provide further details about your issue? How do you plan to use this hook?

By the way, If you're interested, we're open to contributions if you'd like to add this feature.

alicanerdurmaz avatar Aug 17 '23 14:08 alicanerdurmaz

Hello @alicanerdurmaz, hope you're doing great.

Yes sure. So, refine has almost every kind of hook we need for authentication except the useVerify hook.

Let's take Appwrite as a use case here. Suppose I want the users to verify their email addresses, so I would have to use the verify method of the account instance.

First we need to send a verification link to the user's email address:

import { Client, Account } from "appwrite";

const client = new Client();

const account = new Account(client);

client
    .setEndpoint('YOUR_CLOUDWRITE_API_ENDPOINT')
    .setProject('YOUR_CLOUDWRITE_PROJECT_ID');

await account.createVerification('https://example.com');

Then the provided link should redirect the user back to the app and allow them to complete the verification process by verifying both the userId and secret params:

import { Client, Account } from "appwrite";

const client = new Client();

const account = new Account(client);

client
    .setEndpoint('YOUR_CLOUDWRITE_API_ENDPOINT')
    .setProject('YOUR_CLOUDWRITE_PROJECT_ID');

await account.updateVerification('[USER_ID]', '[SECRET]');

Instead, we can make the verification process easier with the useVerify hook. Just to make the hook clearer it would be something like this:

export const authProvider: AuthBindings = {
  createVerification: async ({ verification_link, redirect_url })  => {
    try {
      await account.createVerification(verification_link,);
      return {
        success: true,
        redirectTo: {redirect_url},
      };
    } catch (error) {
      const { type, message, code } = error as AppwriteException;
      return {
        success: false,
        error: {
          message,
          name: `${code} - ${type}`,
        },
      };
    }
  },
  updateVerification: async ({ user_id, secret, redirect_url })  => {
    try {
     await account.updateVerification(user_id, secret);
      return {
        success: true,
        redirectTo: {redirect_url},
      };
    } catch (error) {
      const { type, message, code } = error as AppwriteException;
      return {
        success: false,
        error: {
          message,
          name: `${code} - ${type}`,
        },
      };
    }
   },
 }

And yes I would like to work on this feature. 😀

MahirMahdi avatar Aug 17 '23 16:08 MahirMahdi

Hey @MahirMahdi, at first glance this looks more like a backend work than frontend. I understand your use case but not sure if this is very useful for the majority of the users. We'll consider adding this to our roadmap for the future but currently we'll probably won't have any progress for now until the specs are clear and until its decided to be useful.

aliemir avatar Aug 18 '23 13:08 aliemir

Hey @aliemir thanks for looking into it. I appreciate it.😀

MahirMahdi avatar Aug 18 '23 15:08 MahirMahdi

is anybody working on this?

akhil888binoy avatar Sep 27 '23 16:09 akhil888binoy

Hey @akhil888binoy, no one yet. Do you want me to assign it to you?

BatuhanW avatar Sep 27 '23 17:09 BatuhanW

yeah sure , happy to work on it

akhil888binoy avatar Sep 27 '23 18:09 akhil888binoy

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jan 20 '24 10:01 stale[bot]

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Mar 22 '24 09:03 stale[bot]