Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Login Error with Token Generator #1

Open
mauromn1992 opened this issue Jun 7, 2022 · 2 comments
Open

Login Error with Token Generator #1

mauromn1992 opened this issue Jun 7, 2022 · 2 comments

Comments

@mauromn1992
Copy link

Route Login:

  Route.post('/login', async ({ auth, request, response }) => {
    const email = request.input('email')
    const password = request.input('password')

    await prisma.user.findUnique(
      { where: { email: String(email) } }
    ).then(async (user: User) => {

      if (await Hash.verify(user.password, password)) {
        const token = await auth.use('api').generate(user)
        return token
      }

    })

message:
E_IOC_LOOKUP_FAILED: Cannot resolve \"Adonis/Lucid/Database\" namespace from the IoC Container"

stack:
IocLookupException: E_IOC_LOOKUP_FAILED: Cannot resolve \"Adonis/Lucid/Database\" namespace from the IoC Container\n at Function.lookupFailed (/com.docker.devenvironments.code/backend/node_modules/@adonisjs/fold/build/src/Exceptions/IocLookupException.js:18:16)\n at Ioc.lookupOrFail (/com.docker.devenvironments.code/backend/node_modules/@adonisjs/fold/build/src/Ioc/index.js:254:59)\n at Ioc.use (/com.docker.devenvironments.code/backend/node_modules/@adonisjs/fold/build/src/Ioc/index.js:308:33)\n at AuthManager.makeTokenDatabaseProvider (/com.docker.devenvironments.code/backend/node_modules/@adonisjs/auth/build/src/AuthManager/index.js:79:53)\n at AuthManager.makeTokenProviderInstance (/com.docker.devenvironments.code/backend/node_modules/@adonisjs/auth/build/src/AuthManager/index.js:193:29)\n at AuthManager.makeOatGuard (/com.docker.devenvironments.code/backend/node_modules/@adonisjs/auth/build/src/AuthManager/index.js:104:36)\n at AuthManager.makeGuardInstance (/com.docker.devenvironments.code/backend/node_modules/@adonisjs/auth/build/src/AuthManager/index.js:212:29)\n at AuthManager.makeMapping (/com.docker.devenvironments.code/backend/node_modules/@adonisjs/auth/build/src/AuthManager/index.js:228:21)\n at Auth.use (/com.docker.devenvironments.code/backend/node_modules/@adonisjs/auth/build/src/Auth/index.js:37:58)\n at /com.docker.devenvironments.code/backend/start/routes.ts:37:34

@wahyubucil
Copy link
Owner

May I see your config/auth.ts? I think you forgot to remove the import statement on the config. Because it's not recommended to use Prisma and Lucid at the same time.

@alexnascimentoti
Copy link

/**

  • Config source: https://git.io/JY0mp
  • Feel free to let us know via PR, if you find something broken in this config
  • file.
    */

import { AuthConfig } from '@IOC:Adonis/Addons/Auth'

/*
Authentication Mapping
--------------------------------------------------------------------------

|
| List of available authentication mapping. You must first define them
| inside the contracts/auth.ts file before mentioning them here.
|
/
const authConfig: AuthConfig = {
guard: 'api',
guards: {
/

|--------------------------------------------------------------------------
| OAT Guard
|--------------------------------------------------------------------------
|
| OAT (Opaque access tokens) guard uses database backed tokens to authenticate
| HTTP request. This guard DOES NOT rely on sessions or cookies and uses
| Authorization header value for authentication.
|
| Use this guard to authenticate mobile apps or web clients that cannot rely
| on cookies/sessions.
|
*/
api: {
driver: 'oat',

  /*
  |--------------------------------------------------------------------------
  | Tokens provider
  |--------------------------------------------------------------------------
  |
  | Uses SQL database for managing tokens. Use the "database" driver, when
  | tokens are the secondary mode of authentication.
  | For example: The Github personal tokens
  |
  | The foreignKey column is used to make the relationship between the user
  | and the token. You are free to use any column name here.
  |
  */
  tokenProvider: {
    type: 'api',
    driver: 'database',
    table: 'api_tokens',
    foreignKey: 'user_id',
  },

  provider: {
    driver: 'prisma',
    identifierKey: 'id',
    uids: ['email'],
    model: 'user',
  },
},

},
}

export default authConfig

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants