Skip to content

Commit

Permalink
Removed unstable_ prefix from session middleware (#1607)
Browse files Browse the repository at this point in the history
(major)
  • Loading branch information
Steffan-Harris committed Dec 15, 2020
1 parent e53f1b2 commit 12d93c7
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions examples/auth/blitz.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const {sessionMiddleware, unstable_simpleRolesIsAuthorized} = require("@blitzjs/server")
const {sessionMiddleware, simpleRolesIsAuthorized} = require("@blitzjs/server")
const withBundleAnalyzer = require("@next/bundle-analyzer")({
enabled: process.env.ANALYZE === "true",
})

module.exports = withBundleAnalyzer({
middleware: [
sessionMiddleware({
unstable_isAuthorized: unstable_simpleRolesIsAuthorized,
isAuthorized: simpleRolesIsAuthorized,
sessionExpiryMinutes: 4,
}),
],
Expand Down
4 changes: 2 additions & 2 deletions examples/fauna/blitz.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { sessionMiddleware, unstable_simpleRolesIsAuthorized } = require("@blitzjs/server")
const { sessionMiddleware, simpleRolesIsAuthorized } = require("@blitzjs/server")
const { GraphQLClient, gql } = require("graphql-request")

const graphQLClient = new GraphQLClient("https://graphql.fauna.com/graphql", {
Expand All @@ -20,7 +20,7 @@ const normalizeSession = (faunaSession) => {
module.exports = {
middleware: [
sessionMiddleware({
unstable_isAuthorized: unstable_simpleRolesIsAuthorized,
isAuthorized: simpleRolesIsAuthorized,
getSession: async (handle) => {
const { findSessionByHandle: session } = await graphQLClient.request(
gql`
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/supertokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export type SessionConfig = {
createSession: (session: SessionModel) => Promise<SessionModel>
updateSession: (handle: string, session: Partial<SessionModel>) => Promise<SessionModel>
deleteSession: (handle: string) => Promise<SessionModel>
unstable_isAuthorized: (userRoles: string[], input?: any) => boolean
isAuthorized: (userRoles: string[], input?: any) => boolean
}

export interface SessionContextBase {
Expand Down
4 changes: 2 additions & 2 deletions packages/generator/templates/app/blitz.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const { sessionMiddleware, unstable_simpleRolesIsAuthorized } = require("@blitzjs/server")
const { sessionMiddleware, simpleRolesIsAuthorized } = require("@blitzjs/server")

module.exports = {
middleware: [
sessionMiddleware({
unstable_isAuthorized: unstable_simpleRolesIsAuthorized,
isAuthorized: simpleRolesIsAuthorized,
}),
],
/* Uncomment this to customize the webpack config
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/supertokens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import fetch from "isomorphic-unfetch"
import {apiResolver} from "next/dist/next-server/server/api-utils"
import listen from "test-listen"
import {rpcApiHandler} from "./rpc"
import {sessionMiddleware, unstable_simpleRolesIsAuthorized} from "./supertokens"
import {sessionMiddleware, simpleRolesIsAuthorized} from "./supertokens"

const isIsoDate = (str: string) => {
if (!/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/.test(str)) return false
Expand Down Expand Up @@ -137,7 +137,7 @@ async function mockServer<TInput, TResult>(
const handler = rpcApiHandler(
resolverModule,
[
sessionMiddleware({unstable_isAuthorized: unstable_simpleRolesIsAuthorized}),
sessionMiddleware({isAuthorized: simpleRolesIsAuthorized}),
...(resolverModule.middleware || []),
],
dbConnectorFn,
Expand Down
12 changes: 6 additions & 6 deletions packages/server/src/supertokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ const defaultConfig: SessionConfig = {
}
},
deleteSession: (handle) => getDb().session.delete({where: {handle}}),
unstable_isAuthorized: () => {
throw new Error("No unstable_isAuthorized implementation provided")
isAuthorized: () => {
throw new Error("No isAuthorized implementation provided")
},
}

export function unstable_simpleRolesIsAuthorized(userRoles: string[], input?: any) {
export function simpleRolesIsAuthorized(userRoles: string[], input?: any) {
// No roles required, so all roles allowed
if (!input) return true

Expand All @@ -111,8 +111,8 @@ let config: Required<SessionConfig>
// --------------------------------
export const sessionMiddleware = (sessionConfig: Partial<SessionConfig> = {}): Middleware => {
assert(
sessionConfig.unstable_isAuthorized,
"You must provide an authorization implementation to sessionMiddleware as unstable_isAuthorized(userRoles, input)",
sessionConfig.isAuthorized,
"You must provide an authorization implementation to sessionMiddleware as isAuthorized(userRoles, input)",
)
config = {
...defaultConfig,
Expand Down Expand Up @@ -223,7 +223,7 @@ export class SessionContextClass implements SessionContext {
isAuthorized(input?: any) {
if (!this.userId) return false

return config.unstable_isAuthorized(this.roles, input)
return config.isAuthorized(this.roles, input)
}

async create(publicData: PublicData, privateData?: Record<any, any>) {
Expand Down
4 changes: 2 additions & 2 deletions recipes/theme-ui/templates/config/blitz.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {sessionMiddleware, unstable_simpleRolesIsAuthorized} = require("@blitzjs/server")
const {sessionMiddleware, simpleRolesIsAuthorized} = require("@blitzjs/server")

const withMDX = require("@next/mdx")({
extension: /\.mdx?$/,
Expand All @@ -7,7 +7,7 @@ const withMDX = require("@next/mdx")({
module.exports = withMDX({
middleware: [
sessionMiddleware({
unstable_isAuthorized: unstable_simpleRolesIsAuthorized,
isAuthorized: simpleRolesIsAuthorized,
}),
],
/* Uncomment this to customize the webpack config
Expand Down

0 comments on commit 12d93c7

Please sign in to comment.