-
Notifications
You must be signed in to change notification settings - Fork 1
feat(core): introduce identity option to enable schema validation #130
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b4a257d
feat(core): introduce identity option to enable schema validation
halvaradop cb5258c
chore(core): fix types and improve type-safe
halvaradop c77a4eb
chore(core): implement identity schema validation
halvaradop c4d41bf
chore(core): clean up code and add new tests
halvaradop e4679f3
fix(core): correct OAuth provider type inference with identity option
halvaradop 8ffac71
chore: apply coderabbit
halvaradop b4e05d3
chore: re-export types
halvaradop File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,3 +1,29 @@ | ||
| import type { User } from "@/@types/session.ts" | ||
| import type { AuthInstance } from "@/@types/config.ts" | ||
| import type { ZodObject, ZodRawShape, ZodTypeAny, infer as Infer } from "zod/v4" | ||
|
|
||
| export type Prettify<T> = { [K in keyof T]: T[K] } | ||
|
|
||
| export type LiteralUnion<T extends U, U = string> = T | (U & Record<never, never>) | ||
|
|
||
| export type EditableShape<T extends ZodRawShape> = { | ||
| [K in keyof T]: T[K] extends ZodObject<infer Inner extends ZodRawShape> ? ZodObject<EditableShape<Inner>> : ZodTypeAny | ||
| } | ||
|
|
||
| export type Merge<A, B> = Omit<A, keyof B> & B | ||
|
|
||
| export type ShapeToObject<S extends ZodRawShape = ZodRawShape> = Merge< | ||
| { | ||
| [K in keyof S]: Infer<S[K]> | ||
| }, | ||
| User | ||
| > | ||
|
|
||
| export type DeepRequired<T> = { | ||
| [K in keyof T]-?: T[K] extends object ? DeepRequired<T[K]> : T[K] | ||
| } | ||
|
|
||
| export type InferAuthIdentity<Config> = Config extends AuthInstance<infer Identity> ? Prettify<Identity> : User | ||
|
|
||
| export type InferShape<T extends ZodObject> = T["shape"] | ||
| export type InferIdentity<T extends ZodObject> = ShapeToObject<InferShape<T>> |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,30 +1,35 @@ | ||
| import { z } from "zod/v4" | ||
| import { updateSession } from "@/api/updateSession.ts" | ||
| import { createEndpoint, createEndpointConfig } from "@aura-stack/router" | ||
| import { updateSession } from "@/api/updateSession.ts" | ||
| import type { User } from "@/@types/session.ts" | ||
| import type { IdentityConfig } from "@/@types/config.ts" | ||
|
|
||
| export const config = createEndpointConfig({ | ||
| schemas: { | ||
| body: z.object({ | ||
| name: z.string().optional(), | ||
| email: z.email().optional(), | ||
| image: z.string().optional(), | ||
| expires: z.string().optional(), | ||
| }), | ||
| }, | ||
| }) | ||
| export const config = (identity: IdentityConfig) => { | ||
| return createEndpointConfig({ | ||
| schemas: { | ||
| body: z.object({ | ||
| user: identity.schema?.partial().optional(), | ||
| expires: z.coerce.date().optional(), | ||
| }), | ||
|
halvaradop marked this conversation as resolved.
|
||
| }, | ||
| }) | ||
|
halvaradop marked this conversation as resolved.
|
||
| } | ||
|
|
||
| export const updateSessionAction = createEndpoint( | ||
| "PATCH", | ||
| "/session", | ||
| async (ctx) => { | ||
| const updated = await updateSession({ | ||
| ctx: ctx.context, | ||
| headers: ctx.request.headers, | ||
| session: { | ||
| user: ctx.body, | ||
| }, | ||
| }) | ||
| return Response.json(updated, { status: updated.updated ? 200 : 401 }) | ||
| }, | ||
| config | ||
| ) | ||
| export const updateSessionAction = (identity: IdentityConfig) => { | ||
| return createEndpoint( | ||
| "PATCH", | ||
| "/session", | ||
| async (ctx) => { | ||
| const updated = await updateSession({ | ||
| ctx: ctx.context, | ||
| headers: ctx.request.headers, | ||
| session: { | ||
| user: ctx.body.user as User, | ||
| expires: ctx.body.expires?.toISOString(), | ||
| }, | ||
| }) | ||
| return Response.json(updated, { status: updated.updated ? 200 : 401 }) | ||
| }, | ||
| config(identity) | ||
| ) | ||
| } | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.