Skip to content

Login method of the AuthProvider when creating a refine project using the CLI #325

Description

@nibble0101

When you bootstrap a new refine project using the refine command line tool and select Strapi v4 as Data Provider, a src/authProvider.ts file is created. Of particular interest is the login method of the authProvider. Notice how the username field is being destructured. When you console.log(username), you will get undefined. I suspect it has something to do with use of AuthPage instead of LoginPage (which is now deprecated).

You should be destructuring email instead. I feel a beginner might find it difficult to see what is going on.

export const authProvider: AuthProvider = {
  login: async ({ username, password }) => {
    const { data, status } = await strapiAuthHelper.login(username, password);
     // console.log(username)  undefined
    if (status === 200) {
      localStorage.setItem(TOKEN_KEY, data.jwt);

      // set header axios instance
      axiosInstance.defaults.headers.common = {
        Authorization: `Bearer ${data.jwt}`,
      };

      return Promise.resolve();
    }
    return Promise.reject();
  },
};

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions