Skip to content

Commit

Permalink
blitz-auth: useAuthenticatedBlitzContext returns AuthenticatedCtx (
Browse files Browse the repository at this point in the history
…#4198)

Co-authored-by: Brandon Bayer <[email protected]>
  • Loading branch information
siddhsuresh and flybayer authored Aug 17, 2023
1 parent 0f1beb5 commit 8b01175
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/fresh-camels-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blitzjs/auth": patch
---

Updated `useAuthenticatedBlitzContext` to now return `AuthenticatedCtx`
4 changes: 3 additions & 1 deletion packages/blitz-auth/src/server/auth-sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
log,
baseLogger,
chalk,
AuthenticatedCtx,
} from "blitz"
import {
EmptyPublicData,
Expand Down Expand Up @@ -219,7 +220,7 @@ export async function useAuthenticatedBlitzContext({
redirectTo?: string | RouteUrlObject
redirectAuthenticatedTo?: string | RouteUrlObject | ((ctx: Ctx) => string | RouteUrlObject)
role?: string | string[]
}): Promise<void> {
}): Promise<AuthenticatedCtx> {
const log = baseLogger().getSubLogger({name: "useAuthenticatedBlitzContext"})
const customChalk = new chalk.Instance({
level: log.settings.type === "json" ? 0 : chalk.level,
Expand Down Expand Up @@ -268,6 +269,7 @@ export async function useAuthenticatedBlitzContext({
redirect(redirectTo)
}
}
return ctx as AuthenticatedCtx
}

const makeProxyToPublicData = <T extends SessionContextClass>(ctxClass: T): T => {
Expand Down
2 changes: 1 addition & 1 deletion packages/blitz-auth/src/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ declare module "blitz" {
export interface Ctx {
session: SessionContext
}
export interface AuthenticatedMiddlewareCtx extends Omit<Ctx, "session"> {
export interface AuthenticatedCtx extends Omit<Ctx, "session"> {
session: AuthenticatedSessionContext
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/blitz-rpc/src/server/resolvers/resolver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {SessionContext, SessionContextBase} from "@blitzjs/auth"
import {Await, Ctx, EnsurePromise, AuthenticatedMiddlewareCtx} from "blitz"
import {Await, Ctx, EnsurePromise, AuthenticatedCtx} from "blitz"
import type {input as zInput, output as zOutput, ZodTypeAny} from "zod"

export type ParserType = "sync" | "async"
Expand Down Expand Up @@ -271,7 +271,7 @@ interface ResolverAuthorize {
<T, C = Ctx>(...args: Parameters<SessionContextBase["$authorize"]>): (
input: T,
ctx: C,
) => ResultWithContext<T, AuthenticatedMiddlewareCtx>
) => ResultWithContext<T, AuthenticatedCtx>
}

const authorize: ResolverAuthorize = (...args) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/blitz/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {UrlObject} from "url"
// Context for plugins to declaration merge stuff into
export interface Ctx {}

export interface AuthenticatedMiddlewareCtx {}
export interface AuthenticatedCtx {}

export type CodegenField = {
component: string
Expand All @@ -17,7 +17,7 @@ export interface RouteUrlObject extends Pick<UrlObject, "pathname" | "query" | "
href: string
}

export interface AuthenticatedMiddlewareCtx {}
export interface AuthenticatedCtx {}

export type EventHooks = {
onSessionCreated?: OnSessionCreated
Expand Down

0 comments on commit 8b01175

Please sign in to comment.