Small Nest.js microservice proof of concept to handle Authentification&Authorization via GraphQL interface and PostgreSQL db.
Prerequisites:
- Deployed Vercel PosgreSQL db
- .env populated with variables from this db 2.1 .env has JWT_SECRET variable, that can be any string
pnpm install
pnpm prisma generate
pnpm prisma migrate dev --name init
pnpm prisma migrate deploy
psql -h your-host -U your-user -d your-database
\dn # to check schemas
\dt your_schema.* # to check tables in schema
pnpm start
go to http://localhost:3000/graphql.
Testing will be done inside of GraphQL playground
There are 4 unauthorized functions:
mutation {
register(email: "name@users.com", password: "password", role: ADMIN)
}
mutation {
findUsersByRole(role: ADMIN)
}
mutation {
findOneByEmail(email: "name@users.com")
}
- First
mutation {
login(email: "name@users.com", password: "password") {
access_token
}
}
-
Then open f12->Application->Cookies->Create new cookie with name of access_token and value that you copied
-
Then in http://localhost:3000/graphql. click Settings in top-right corner and change following line like this: "request.credentials": "include"
-
This is done, because GraphQL playground has broken Cookies setting and is not allowing to attach them easily
-
Try to create new user via admin rights:
mutation {
createUser(email: "created@users.com")
}
- Thanks for attention