Skip to content

Commit

Permalink
Change the user repository and transform jwt secret into .env
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrodecf committed Jan 27, 2024
1 parent f5066e0 commit 2b0aba0
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 8 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
NODE_ENV=dev
PORT=3333
DATABASE_URL="postgresql://docker:docker@localhost:8080/orange-db?schema=public"
JWT_TOKEN=
5 changes: 1 addition & 4 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ app.register(userRoutes)
app.register(authRoutes)

app.register(fastifyJwt, {
secret: 'squad40',
// sign: {
// expiresIn: '10s',
// },
secret: env.JWT_SECRET,
})

app.setErrorHandler((error, _, response) => {
Expand Down
4 changes: 2 additions & 2 deletions src/controller/session/authUser.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { FastifyReply, FastifyRequest } from 'fastify'
import { InMemoryUserRepository } from '../../repositories/in-memory-db/inMemoryUserRepository'
import { AuthUserUseCase } from '../../use-cases/authUserUseCase'
import { z } from 'zod'
import { PrismaUsersRepository } from '../../repositories/prisma/prisma-users-repository'

export async function authUser(
request: FastifyRequest,
response: FastifyReply,
) {

const userRepository = new InMemoryUserRepository()
const userRepository = new PrismaUsersRepository()
const authUserUseCase = new AuthUserUseCase(userRepository)

const AuthUserUseCaseSchema = z.object({
Expand Down
3 changes: 1 addition & 2 deletions src/controller/user/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ import { registerUser } from './registerUser'
export async function userRoutes(app: FastifyInstance) {
app.post('/user', registerUser)
app.get('/user/:id', getUserById)
// app.get('/user', getUserByEmail)
app.get('/user', { onRequest: [verifyJWT] }, getUserByEmail)
app.get('/user', getUserByEmail)
}
1 change: 1 addition & 0 deletions src/env/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const envSchema = z.object({
NODE_ENV: z.enum(['dev', 'test', 'production']).default('dev'),
PORT: z.coerce.number().default(3333),
DATABASE_URL: z.string(),
JWT_SECRET: z.string()
})

const _env = envSchema.safeParse(process.env)
Expand Down

0 comments on commit 2b0aba0

Please sign in to comment.