create-bison-app
Advanced tools
{ | ||
"name": "create-bison-app", | ||
"version": "1.12.0-canary.5", | ||
"version": "1.12.0-canary.6", | ||
"description": "Creates a production-ready full-stack Jamstack app", | ||
@@ -62,3 +62,3 @@ "license": "MIT", | ||
}, | ||
"gitHead": "d7de8bacf0630e61b4b6454b7dee9e1292474fb9" | ||
"gitHead": "1865c54f4420e886ba81c435ac509e20b6b49eb0" | ||
} |
@@ -34,3 +34,3 @@ import { IncomingMessage } from 'http'; | ||
prisma: PrismaClient; | ||
user: User; | ||
user: User | null; | ||
}; |
@@ -1,3 +0,5 @@ | ||
import { objectType, inputObjectType } from 'nexus'; | ||
import { inputObjectType, objectType } from 'nexus'; | ||
import { NotFoundError } from '../errors'; | ||
// Profile Type | ||
@@ -15,4 +17,4 @@ export const Profile = objectType({ | ||
type: 'User', | ||
resolve: (parent, _, context) => { | ||
return context.prisma.profile | ||
resolve: async (parent, _, context) => { | ||
const user = await context.prisma.profile | ||
.findUnique({ | ||
@@ -22,2 +24,8 @@ where: { id: parent.id }, | ||
.user(); | ||
if (!user) { | ||
throw new NotFoundError('User not found'); | ||
} | ||
return user; | ||
}, | ||
@@ -24,0 +32,0 @@ }); |
import { hashPassword } from '../../services/auth'; | ||
import { Role, UserCreateInput } from '../../types'; | ||
import { Role } from '../../types'; | ||
import { seedUsers } from '../seeds/users'; | ||
import { prisma } from '../../lib/prisma'; | ||
import { Prisma } from '@prisma/client'; | ||
@@ -11,3 +13,3 @@ // HR: Hey, we've had a few more employees join -- can you create an account for them?! | ||
const main = async () => { | ||
const newEmployees: UserCreateInput[] = [ | ||
const newEmployees: Prisma.UserCreateInput[] = [ | ||
{ | ||
@@ -14,0 +16,0 @@ profile: { |
@@ -19,3 +19,3 @@ import { Command } from 'commander'; | ||
child.on('exit', function (code) { | ||
process.exit(code); | ||
process.exit(code || 1); | ||
}); | ||
@@ -22,0 +22,0 @@ }; |
@@ -0,4 +1,4 @@ | ||
import { Prisma, Role } from '@prisma/client'; | ||
import { hashPassword } from '../../../services/auth'; | ||
import { Role, UserCreateInput } from '../../../types'; | ||
// ********************************************* | ||
@@ -10,3 +10,3 @@ // ** DEVELOPMENT DATA SET | ||
const initialDevUsers: UserCreateInput[] = [ | ||
const initialDevUsers: Prisma.UserCreateInput[] = [ | ||
{ | ||
@@ -31,3 +31,3 @@ email: 'barry.allen@speedforce.net', | ||
const initialProdUsers: UserCreateInput[] = [ | ||
const initialProdUsers: Prisma.UserCreateInput[] = [ | ||
{ | ||
@@ -52,3 +52,3 @@ email: 'apps@echobind.com', | ||
export const userSeedData: UserCreateInput[] = | ||
export const userSeedData: Prisma.UserCreateInput[] = | ||
appEnv === 'production' ? initialProdUsers : initialDevUsers; |
@@ -1,7 +0,9 @@ | ||
import { User, UserCreateInput } from '../../../types'; | ||
import { Prisma } from '@prisma/client'; | ||
import { prisma } from '../../../lib/prisma'; | ||
import { User } from '../../../types'; | ||
type SeedUserResult = Pick<User, 'id' | 'email'>; | ||
export const seedUsers = async (users: UserCreateInput[]): Promise<SeedUserResult[]> => { | ||
export const seedUsers = async (users: Prisma.UserCreateInput[]): Promise<SeedUserResult[]> => { | ||
const userPromiseArray = users.map( | ||
@@ -8,0 +10,0 @@ async (user): Promise<SeedUserResult> => |
@@ -26,2 +26,12 @@ /** | ||
const getAppSecret = (): string => { | ||
const appSecret = process.env.APP_SECRET; | ||
if (!appSecret) { | ||
throw new Error('APP_SECRET is not set'); | ||
} | ||
return appSecret; | ||
}; | ||
/** | ||
@@ -32,3 +42,3 @@ * Signs a JWT for the provided user | ||
export const appJwtForUser = (user: Partial<User>): string => { | ||
return jwt.sign({ userId: user.id }, process.env.APP_SECRET); | ||
return jwt.sign({ userId: user.id }, getAppSecret()); | ||
}; | ||
@@ -45,3 +55,3 @@ | ||
try { | ||
return jwt.verify(token, process.env.APP_SECRET) as JWT; | ||
return jwt.verify(token, getAppSecret()) as JWT; | ||
} catch (e) { | ||
@@ -48,0 +58,0 @@ return; |
@@ -9,4 +9,8 @@ import { Role, Profile, User } from '@prisma/client'; | ||
*/ | ||
export const isAdmin = (user: Partial<User>): boolean => { | ||
return user?.roles.includes(Role.ADMIN); | ||
export const isAdmin = (user: Partial<User> | null): boolean => { | ||
if (!user?.roles) { | ||
return false; | ||
} | ||
return user.roles.includes(Role.ADMIN); | ||
}; | ||
@@ -13,0 +17,0 @@ |
@@ -15,3 +15,3 @@ import childProcess from 'child_process'; | ||
const match = process.env.DATABASE_URL.match(/schema=(.*)(&.*)*$/); | ||
const match = process.env.DATABASE_URL?.match(/schema=(.*)(&.*)*$/); | ||
const schema = match ? match[1] : 'public'; | ||
@@ -18,0 +18,0 @@ |
@@ -7,3 +7,3 @@ { | ||
"skipLibCheck": true, | ||
"strict": false, | ||
"strict": true, | ||
"forceConsistentCasingInFileNames": true, | ||
@@ -10,0 +10,0 @@ "noEmit": true, |
@@ -1,2 +0,2 @@ | ||
import { ErrorOption } from 'react-hook-form'; | ||
import { UseFormSetError } from 'react-hook-form'; | ||
@@ -6,3 +6,6 @@ /** | ||
*/ | ||
export function setErrorsFromGraphQLErrors(setError: SetErrorFn, errors: ErrorResponse[]) { | ||
export function setErrorsFromGraphQLErrors( | ||
setError: UseFormSetError<any>, | ||
errors: ErrorResponse[] | ||
) { | ||
return (errors || []).forEach((e) => { | ||
@@ -16,4 +19,2 @@ const errorObjects = e.extensions.invalidArgs || {}; | ||
type SetErrorFn = (e: string, obj: ErrorOption) => void; | ||
interface ErrorResponse { | ||
@@ -20,0 +21,0 @@ extensions: { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
161128
1.48%126
1.61%3018
2.55%