Initial commit
This commit is contained in:
25
api/src/lib/auth.ts
Normal file
25
api/src/lib/auth.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Once you are ready to add authentication to your application
|
||||
* you'll build out requireAuth() with real functionality. For
|
||||
* now we just return `true` so that the calls in services
|
||||
* have something to check against, simulating a logged
|
||||
* in user that is allowed to access that service.
|
||||
*
|
||||
* See https://redwoodjs.com/docs/authentication for more info.
|
||||
*/
|
||||
export const isAuthenticated = () => {
|
||||
return true
|
||||
}
|
||||
|
||||
export const hasRole = ({ roles }) => {
|
||||
return roles !== undefined
|
||||
}
|
||||
|
||||
// This is used by the redwood directive
|
||||
// in ./api/src/directives/requireAuth
|
||||
|
||||
// Roles are passed in by the requireAuth directive if you have auth setup
|
||||
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
||||
export const requireAuth = ({ roles }) => {
|
||||
return isAuthenticated()
|
||||
}
|
||||
21
api/src/lib/db.ts
Normal file
21
api/src/lib/db.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
// See https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client/constructor
|
||||
// for options.
|
||||
|
||||
import { PrismaClient } from '@prisma/client'
|
||||
|
||||
import { emitLogLevels, handlePrismaLogging } from '@redwoodjs/api/logger'
|
||||
|
||||
import { logger } from './logger'
|
||||
|
||||
/*
|
||||
* Instance of the Prisma Client
|
||||
*/
|
||||
export const db = new PrismaClient({
|
||||
log: emitLogLevels(['info', 'warn', 'error']),
|
||||
})
|
||||
|
||||
handlePrismaLogging({
|
||||
db,
|
||||
logger,
|
||||
logLevels: ['info', 'warn', 'error'],
|
||||
})
|
||||
17
api/src/lib/logger.ts
Normal file
17
api/src/lib/logger.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { createLogger } from '@redwoodjs/api/logger'
|
||||
|
||||
/**
|
||||
* Creates a logger with RedwoodLoggerOptions
|
||||
*
|
||||
* These extend and override default LoggerOptions,
|
||||
* can define a destination like a file or other supported pino log transport stream,
|
||||
* and sets whether or not to show the logger configuration settings (defaults to false)
|
||||
*
|
||||
* @param RedwoodLoggerOptions
|
||||
*
|
||||
* RedwoodLoggerOptions have
|
||||
* @param {options} LoggerOptions - defines how to log, such as redaction and format
|
||||
* @param {string | DestinationStream} destination - defines where to log, such as a transport stream or file
|
||||
* @param {boolean} showConfig - whether to display logger configuration on initialization
|
||||
*/
|
||||
export const logger = createLogger({})
|
||||
Reference in New Issue
Block a user