Search code examples
vuejs2nuxt.jsnuxt-strapi

how to modify the $strapi.login({}) default route in nuxt(custom login)


I am using nuxt-strapi and I am authentication user by otp and for that I want to use $strapi.login() but the issue is the default endpoint for strapi login is auth/local which requires email and password but I want to modify it and use mobile number. I dont know how to modify the route for that so is there any option like in $auth I can modify the the login route


Solution

  • The nuxt-strapi module doesn't allow you to change the login URL. What I would do in your case is directly call the OTP API endpoint and set the token manually.

    const token = await this.$strapi.$http.$post('otp/endpoint', {tel}) 
    await this.$strapi.setToken(token)
    await this.$strapi.fetchUser() //to get the user information
    //or get the user via $http and set it manually
    this.$strapi.setUser(user)
    

    see for more info https://strapi.nuxtjs.org/strapi