BLOG-136 Dashboard route and frontend authentication #137

Merged
squid merged 10 commits from BLOG-136_create_dashboard_route into main 2025-10-13 20:33:36 +08:00
Owner

Description

  • Create a dashboard layout (with a navigation sidebar)
  • Only logged in users are able to access (others 404)

Package Changes

shadcn-svelte

{
  "@lucide/svelte": "^0.545.0",
  "clsx": "^2.1.1",
  "tailwind-merge": "^3.3.1",
  "tailwind-variants": "^3.1.1",
  "tw-animate-css": "^1.4.0"
}

Screenshots

Status Screenshot
Logged in image.png
Logged out image.png

Reference

Resolves #136.

Checklist

  • A milestone is set
  • The related issuse has been linked to this branch
### Description - Create a dashboard layout (with a navigation sidebar) - Only logged in users are able to access (others 404) ### Package Changes > shadcn-svelte ```json { "@lucide/svelte": "^0.545.0", "clsx": "^2.1.1", "tailwind-merge": "^3.3.1", "tailwind-variants": "^3.1.1", "tw-animate-css": "^1.4.0" } ``` ### Screenshots |Status|Screenshot| |-|-| |Logged in|![image.png](/attachments/5d5fc3b9-c15f-43b8-8201-dedeef3c3fb9)| |Logged out|![image.png](/attachments/29683c9f-395c-4dd8-892f-dc21df2dd0cc)| ### Reference Resolves #136. ### Checklist - [x] A milestone is set - [x] The related issuse has been linked to this branch
108 KiB
119 KiB
squid added this to the 0.4 milestone 2025-10-13 20:29:33 +08:00
squid added 10 commits 2025-10-13 20:29:33 +08:00
feat: implement authentication and user management features
Some checks failed
Frontend CI / build (push) Failing after 58s
365c979878
feat: add custom ErrorPage component for improved error handling
Some checks failed
Frontend CI / build (push) Failing after 53s
f228a9bb4a
chore: update package manager version
Some checks failed
Frontend CI / build (push) Failing after 54s
5e94cceb78
feat: import shadcn
Some checks failed
Frontend CI / build (push) Failing after 58s
07ab4ec157
feat: add 'Label' link to dashboard and create corresponding page
Some checks failed
Frontend CI / build (push) Failing after 59s
d74c5b82c2
feat: redirect from dashboard to post page on load
Some checks failed
Frontend CI / build (push) Failing after 59s
7f03cfa3c9
style: pnpm format
All checks were successful
Frontend CI / build (push) Successful in 1m26s
Auto Comment On PR / add_improve_comment (pull_request) Successful in 17s
PR Title Check / pr-title-check (pull_request) Successful in 17s
bf02d164bc
Collaborator

/improve

/improve
Collaborator

PR Code Suggestions

CategorySuggestion                                                                                                                                    Impact
Possible issue
Correct Zod integer validation

The z.int32() validator is not a standard Zod type and will likely cause runtime
errors during schema parsing. Zod typically uses z.number().int() for integer
validation.

frontend/src/lib/auth/adapter/gateway/userResponseDto.ts [4-8]

 export const UserResponseSchema = z.object({
-	id: z.int32(),
+	id: z.number().int(),
 	displayed_name: z.string(),
 	email: z.email(),
 });
Suggestion importance[1-10]: 9

__

Why: The z.int32() method is not a standard Zod validator and would cause runtime errors. Replacing it with z.number().int() correctly validates integers, preventing potential bugs.

High
Handle unhandled event types

The dispatch method implicitly returns undefined if an AuthEvent other than
CurrentUserLoadedEvent is dispatched, which violates its Promise return type. Add a
default case to handle unknown event types, ensuring a consistent return or error.

frontend/src/lib/auth/adapter/presenter/authBloc.ts [30-33]

 		switch (event.event) {
 			case AuthEventType.CurrentUserLoadedEvent:
 				return this.loadCurrentUser();
+			default:
+				throw new Error(`Unhandled AuthEvent type: ${event.event}`);
 		}
Suggestion importance[1-10]: 8

__

Why: The dispatch method's return type Promise<AuthState> is not guaranteed if an unhandled AuthEvent occurs, leading to a potential runtime error. Adding a default case with an error throw ensures type consistency and robust error handling.

Medium
## PR Code Suggestions ✨ <!-- --> <table><thead><tr><td><strong>Category</strong></td><td align=left><strong>Suggestion&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </strong></td><td align=center><strong>Impact</strong></td></tr><tbody><tr><td rowspan=2>Possible issue</td> <td> <details><summary>Correct Zod integer validation</summary> ___ **The <code>z.int32()</code> validator is not a standard Zod type and will likely cause runtime <br>errors during schema parsing. Zod typically uses <code>z.number().int()</code> for integer <br>validation.** [frontend/src/lib/auth/adapter/gateway/userResponseDto.ts [4-8]](https://git.squidspirit.com/squid/blog/src/branch/BLOG-136_create_dashboard_route/frontend/src/lib/auth/adapter/gateway/userResponseDto.ts#L4-L8) ```diff export const UserResponseSchema = z.object({ - id: z.int32(), + id: z.number().int(), displayed_name: z.string(), email: z.email(), }); ``` <details><summary>Suggestion importance[1-10]: 9</summary> __ Why: The `z.int32()` method is not a standard Zod validator and would cause runtime errors. Replacing it with `z.number().int()` correctly validates integers, preventing potential bugs. </details></details></td><td align=center>High </td></tr><tr><td> <details><summary>Handle unhandled event types</summary> ___ **The <code>dispatch</code> method implicitly returns <code>undefined</code> if an <code>AuthEvent</code> other than <br><code>CurrentUserLoadedEvent</code> is dispatched, which violates its <code>Promise<AuthState></code> return type. Add a <br>default case to handle unknown event types, ensuring a consistent return or error.** [frontend/src/lib/auth/adapter/presenter/authBloc.ts [30-33]](https://git.squidspirit.com/squid/blog/src/branch/BLOG-136_create_dashboard_route/frontend/src/lib/auth/adapter/presenter/authBloc.ts#L30-L33) ```diff switch (event.event) { case AuthEventType.CurrentUserLoadedEvent: return this.loadCurrentUser(); + default: + throw new Error(`Unhandled AuthEvent type: ${event.event}`); } ``` <details><summary>Suggestion importance[1-10]: 8</summary> __ Why: The `dispatch` method's return type `Promise<AuthState>` is not guaranteed if an unhandled `AuthEvent` occurs, leading to a potential runtime error. Adding a `default` case with an error throw ensures type consistency and robust error handling. </details></details></td><td align=center>Medium </td></tr></tr></tbody></table>
Author
Owner

Ignore bot's comments.

Ignore bot's comments.
squid merged commit e8c5e678d5 into main 2025-10-13 20:33:36 +08:00
squid deleted branch BLOG-136_create_dashboard_route 2025-10-13 20:33:37 +08:00
Sign in to join this conversation.
No description provided.