-
Notifications
You must be signed in to change notification settings - Fork 0
chore: auth reworked #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: auth reworked #108
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,5 @@ | ||
| import { repository } from '@roll-stack/database' | ||
|
|
||
| export default defineEventHandler(async (event) => { | ||
| try { | ||
| const user = event.context.user | ||
| if (!user) { | ||
| throw createError({ | ||
| statusCode: 401, | ||
| message: 'Not logged in', | ||
| }) | ||
| } | ||
|
|
||
| return repository.user.find(user.id) | ||
| } catch (error) { | ||
| throw errorResolver(error) | ||
| } | ||
| return repository.user.find(event.context.user.id) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,5 @@ | ||
| import { repository } from '@roll-stack/database' | ||
|
|
||
| export default defineEventHandler(async (event) => { | ||
| const user = event.context.user | ||
| if (!user) { | ||
| throw createError({ | ||
| statusCode: 401, | ||
| message: 'Not logged in', | ||
| }) | ||
| } | ||
|
|
||
| export default defineEventHandler(async () => { | ||
| return repository.epic.list() | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,5 @@ | ||
| import { repository } from '@roll-stack/database' | ||
|
|
||
| export default defineEventHandler(async (event) => { | ||
| try { | ||
| const user = event.context.user | ||
| if (!user) { | ||
| throw createError({ | ||
| statusCode: 401, | ||
| message: 'Not logged in', | ||
| }) | ||
| } | ||
|
|
||
| return repository.notification.listByUser(user.id) | ||
| } catch (error) { | ||
| throw errorResolver(error) | ||
| } | ||
| return repository.notification.listByUser(event.context.user.id) | ||
| }) | ||
|
Comment on lines
3
to
5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainPotential NPE on event.context.user and inconsistent error handling. Ensure middleware guards this route; consider consistent try/catch with errorResolver like other handlers. Run to confirm middleware coverage and existing error handling conventions: 🏁 Script executed: #!/bin/bash
set -euo pipefail
rg -n 'errorResolver\(' apps/atrium-telegram/server/api | head -n 50
fd -a '01.auth.ts' apps | xargs -I{} sed -n '1,220p' "{}" | rg -n 'event\.context\.user'Length of output: 1665 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Locate and display auth middleware file
auth_file=$(fd '01.auth.ts' apps/atrium-telegram)
echo "Auth middleware file: $auth_file"
sed -n '1,200p' "$auth_file"
# Locate and display Nuxt config file
nuxt_cfg=$(fd 'nuxt.config.ts' apps/atrium-telegram)
echo "Nuxt config file: $nuxt_cfg"
sed -n '1,200p' "$nuxt_cfg"
# Search for middleware registration in config
rg -n 'middleware' -C 3 "$nuxt_cfg"
# List server and middleware directories
find apps/atrium-telegram/server -maxdepth 2 -type d
# Confirm usage of event.context.user across codebase
rg -n 'event\.context\.user' -C 2 apps/atrium-telegramLength of output: 3459 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Display the handler implementation
sed -n '1,200p' apps/atrium-telegram/server/api/notification/my.get.ts
# Check for existing error handling patterns
rg -n 'try' -C 3 apps/atrium-telegram/server/api/notification/my.get.ts || true
rg -n 'errorResolver' -C 3 apps/atrium-telegram/server/api/notification/my.get.ts || trueLength of output: 432 Add try/catch with errorResolver 🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,14 +20,6 @@ export default defineEventHandler(async (event) => { | |
| throw data | ||
| } | ||
|
|
||
| const user = event.context.user | ||
| if (!user) { | ||
| throw createError({ | ||
| statusCode: 401, | ||
| message: 'Not logged in', | ||
| }) | ||
| } | ||
|
|
||
| // Guards: | ||
| // If task not exist | ||
| // If performer is not user | ||
|
|
@@ -38,7 +30,7 @@ export default defineEventHandler(async (event) => { | |
| message: 'Task not found', | ||
| }) | ||
| } | ||
| if (!!task.performerId && task.performerId !== user.id) { | ||
| if (!!task.performerId && task.performerId !== event.context.user.id) { | ||
| throw createError({ | ||
| statusCode: 403, | ||
| message: 'You are not the performer of this task', | ||
|
|
@@ -57,8 +49,8 @@ export default defineEventHandler(async (event) => { | |
| } | ||
|
|
||
| // Clear focus if needed | ||
| if (user.focusedTaskId === taskId) { | ||
| await repository.user.update(user.id, { | ||
| if (event.context.user.focusedTaskId === taskId) { | ||
| await repository.user.update(event.context.user.id, { | ||
| focusedTaskId: null, | ||
| }) | ||
| } | ||
|
|
@@ -75,7 +67,7 @@ export default defineEventHandler(async (event) => { | |
| if (list.chat) { | ||
| const bot = await repository.chat.findNotificationBot(list.chat.id) | ||
| if (bot) { | ||
| const text = prepareBotMessage(user, updatedTask) | ||
| const text = prepareBotMessage(event.context.user, updatedTask) | ||
|
|
||
| // Send message as bot | ||
| await repository.chat.createMessage({ | ||
|
|
@@ -87,18 +79,18 @@ export default defineEventHandler(async (event) => { | |
| } | ||
|
|
||
| // Notify all staff | ||
| if (user.type === 'staff') { | ||
| if (event.context.user.type === 'staff') { | ||
| const users = await repository.user.list() | ||
| const allStaffExceptUser = users.filter((u) => u.type === 'staff' && u.id !== user.id) | ||
| const allStaffExceptUser = users.filter((u) => u.type === 'staff' && u.id !== event.context.user.id) | ||
|
|
||
| for (const staff of allStaffExceptUser) { | ||
| if (staff.notifications.includes('task_completed_atrium')) { | ||
| await repository.notification.create({ | ||
| authorId: user.id, | ||
| authorId: event.context.user.id, | ||
| userId: staff.id, | ||
| taskId: updatedTask.id, | ||
| type: 'task_completed', | ||
| title: `${suffixByGender(['Завершил', 'Завершила'], user.gender)} задачу «${updatedTask.name}»`, | ||
| title: `${suffixByGender(['Завершил', 'Завершила'], event.context.user.gender)} задачу «${updatedTask.name}»`, | ||
| description: updatedTask.report ? updatedTask.report : 'Без отчета', | ||
| }) | ||
|
Comment on lines
+93
to
95
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing import for suffixByGender → runtime/TS error
-import { getLocalizedResolution } from '#shared/utils/helpers'
+import { getLocalizedResolution, suffixByGender } from '#shared/utils/helpers'Also applies to: 106-117 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,14 +20,6 @@ export default defineEventHandler(async (event) => { | |||||||||||||||||||||||||||||||||||||
| throw data | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const user = event.context.user | ||||||||||||||||||||||||||||||||||||||
| if (!user) { | ||||||||||||||||||||||||||||||||||||||
| throw createError({ | ||||||||||||||||||||||||||||||||||||||
| statusCode: 401, | ||||||||||||||||||||||||||||||||||||||
| message: 'Not logged in', | ||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const task = await repository.task.find(taskId) | ||||||||||||||||||||||||||||||||||||||
| if (!task) { | ||||||||||||||||||||||||||||||||||||||
| throw createError({ | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -44,7 +36,7 @@ export default defineEventHandler(async (event) => { | |||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const canEdit = list.chat?.members.some((member) => member.userId === user.id) | ||||||||||||||||||||||||||||||||||||||
| const canEdit = list.chat?.members.some((member) => member.userId === event.context.user.id) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // Guard: if don't have access | ||||||||||||||||||||||||||||||||||||||
| if (!canEdit) { | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -68,7 +60,7 @@ export default defineEventHandler(async (event) => { | |||||||||||||||||||||||||||||||||||||
| if (list.chat) { | ||||||||||||||||||||||||||||||||||||||
| const bot = await repository.chat.findNotificationBot(list.chat.id) | ||||||||||||||||||||||||||||||||||||||
| if (bot) { | ||||||||||||||||||||||||||||||||||||||
| const text = prepareBotMessage(user, task, updatedTask, updatedPerformer) | ||||||||||||||||||||||||||||||||||||||
| const text = prepareBotMessage(event.context.user, task, updatedTask, updatedPerformer) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // Send message as bot | ||||||||||||||||||||||||||||||||||||||
| await repository.chat.createMessage({ | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
61
to
66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion
- const text = prepareBotMessage(event.context.user, task, updatedTask, updatedPerformer)
+ const author = await repository.user.find(event.context.user.id)
+ if (!author) {
+ throw createError({ statusCode: 500, message: 'Author not found' })
+ }
+ const text = prepareBotMessage(author, task, updatedTask, updatedPerformer)📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Unsafe access to event.context.user.id — guard against missing user.
Align with middleware assumptions but fail safe locally to avoid runtime TypeError.
📝 Committable suggestion
🤖 Prompt for AI Agents