adonisjs / auth

Official Authentication package for AdonisJS
https://docs.adonisjs.com/guides/auth/introduction
MIT License
192 stars 65 forks source link

API Token with Seeds & Factories #114

Closed dakiesse closed 6 years ago

dakiesse commented 6 years ago

Hey! How can I make API Token for User via Factories/Seed?

RomainLanz commented 6 years ago

Hey @dakiesse ! 👋

I didn't really understand your question. Also, if it's not an issue in the framework, please ask this question in the forum/discord server.

dakiesse commented 6 years ago

Hey @RomainLanz ,

I meant How to use generating an api token for seeding (How to create token entity for user through seeding) but I have already found a solution for it:

const Config = use('Adonis/Src/Config')
const Auth = use('Adonis/Src/Auth')

class UserSeeder {
  async run () {
    await clearDatabase()

    // main user
    const user = await Factory.model('App/Models/User').create()

    // make token
    const auth = new Auth({}, Config)
    const token = await auth.generate(user)
    console.log('Main user token:', token)

    // ... other code
  }
}
RomainLanz commented 6 years ago

Why would you want to make a JWT token while seeding?

dakiesse commented 6 years ago

I want to make API Token (no JWT). I have been doing because I create a mobile application and I want to test auth. For example, a case when a user is EXISTS and need to auth at mobile application.

RomainLanz commented 6 years ago

Cool 👍

I believe we can close this issue since you found a solution. Feel free to comment again if you want me to reopen it!

mariosantosdev commented 2 years ago

@dakiesse how u find the file Adonis/Src/Auth? You know if in the adonis 5 it's work?