-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Find users by email instead of hard coded userIds. Also simplify seed…
…ing script
- Loading branch information
1 parent
c83b139
commit 1f4d39a
Showing
3 changed files
with
10 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,11 +44,11 @@ const ENV = envSchema.parse(process.env) | |
|
||
const USERS = { | ||
garbo: { | ||
id: 1, | ||
email: '[email protected]', | ||
token: ENV.API_TOKENS.garbo, | ||
}, | ||
alex: { | ||
id: 2, | ||
email: '[email protected]', | ||
token: ENV.API_TOKENS.alex, | ||
}, | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,8 +43,8 @@ export const cache = () => { | |
} | ||
|
||
const USERS = { | ||
garbo: 1, | ||
alex: 2, | ||
garbo: '[email protected]', | ||
alex: '[email protected]', | ||
} | ||
|
||
export const fakeAuth = | ||
|
@@ -55,7 +55,7 @@ export const fakeAuth = | |
if (ENV.API_TOKENS.includes(token)) { | ||
const [username] = token.split(':') | ||
const user = await prisma.user.findFirst({ | ||
where: { id: USERS[username] }, | ||
where: { email: USERS[username] }, | ||
}) | ||
res.locals.user = user | ||
} | ||
|
@@ -93,8 +93,8 @@ export const createMetadata = | |
if (req.method === 'POST') { | ||
// TODO: Find a better way to determine if changes by the current user should count as verified or not | ||
// IDEA: Maybe a column in the User table to determine if this is a trusted editor? And if so, all their changes are automatically "verified". | ||
const verifiedByUserId = | ||
res.locals.user.id === USERS.alex ? USERS.alex : null | ||
const verifiedByUserEmail = | ||
res.locals.user.email === USERS.alex ? USERS.alex : null | ||
|
||
const { comment, source, dataOrigin } = req.body.metadata ?? {} | ||
|
||
|
@@ -108,10 +108,10 @@ export const createMetadata = | |
id: res.locals.user.id, | ||
}, | ||
}, | ||
verifiedBy: verifiedByUserId | ||
verifiedBy: verifiedByUserEmail | ||
? { | ||
connect: { | ||
id: verifiedByUserId, | ||
email: verifiedByUserEmail, | ||
}, | ||
} | ||
: undefined, | ||
|