Skip to content

Commit

Permalink
chore: return projectId on magic link auth
Browse files Browse the repository at this point in the history
  • Loading branch information
luandro committed Feb 11, 2025
1 parent ded6093 commit d2e429b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
17 changes: 16 additions & 1 deletion src/routes/magic-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export default async function magicLinkRoutes(fastify, { serverBearerToken }) {
200: Type.Object({
magicLinkToken: Type.String(),
user: Type.Any(),
projectId: Type.String(),
}),
'4xx': schemas.errorResponse,
},
Expand Down Expand Up @@ -140,7 +141,21 @@ export default async function magicLinkRoutes(fastify, { serverBearerToken }) {
`Magic link token invalidated successfully: ${magicToken}`,
)

return { magicLinkToken: magicToken, user: associatedUser }
const projects = await fastify.comapeo.listProjects()
const project = projects.find(
(p) => p.name === associatedUser.projectName,
)
if (!project) {
fastify.log.error(
`No project found for user with projectName: ${associatedUser.projectName}`,
)
throw errors.notFoundError(
`No project found for user with projectName: ${associatedUser.projectName}`,
)
}
const projectId = project.projectId

return { magicLinkToken: magicToken, user: associatedUser, projectId }
},
})
}
10 changes: 5 additions & 5 deletions src/routes/observations.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ export default async function observationRoutes(
category: Type.Optional(Type.String()),
locale: Type.Optional(Type.String()),
}),
body: Type.Union([schemas.observationToAdd, schemas.observationToUpdate]),
body: Type.Optional(
Type.Union([schemas.observationToAdd, schemas.observationToUpdate]),
),
response: {
200: Type.Object({
versionId: Type.String(),
Expand Down Expand Up @@ -208,8 +210,7 @@ export default async function observationRoutes(

if (effectiveVersionId) {
// Update existing observation
const body = /** @type {Record<string, any>} */ (req.body)

const body = /** @type {Record<string, any>} */ (req.body || {})
// Explicitly reject lat/lon in updates
if ('lat' in body || 'lon' in body) {
throw errors.badRequestError(
Expand Down Expand Up @@ -244,8 +245,7 @@ export default async function observationRoutes(
}

// Create new observation
const body = /** @type {Record<string, any>} */ (req.body)

const body = /** @type {Record<string, any>} */ (req.body || {})
if (typeof body.lat !== 'number' || typeof body.lon !== 'number') {
throw errors.badRequestError(
'lat and lon are required for new observations',
Expand Down
1 change: 1 addition & 0 deletions src/schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export const observationToUpdate = Type.Object({
})

export const observationResult = Type.Object({
versionId: Type.String(),
docId: Type.String(),
createdAt: dateTimeString,
updatedAt: dateTimeString,
Expand Down

0 comments on commit d2e429b

Please sign in to comment.