v0.16.0 Highlights
Deploy to Vercel!
Check out our Example Blog live on Vercel.
Redwood is designed for serverless architecture deployment, and now there are two officially supported deploy targets:
- Netlify
- Vercel
If you would like to try it out, read our deployment documentation.
A huge thank to the @styfle and the team at Vercel, and @thedavidprice and @cannikin for working on this feature!
Role based access control (RBAC)
Hot off @dthyresson’s keystrokes comes RBAC to Redwood! We’ve enhanced the great semantics of our authentication implementation with a few small additions, first off on the API side, tell Redwood which role your currentUser
has:
// src/lib/auth.js
export const getCurrentUser = (decoded) => {
// get user from the database, token, etc.
const user = await db.user.findOne({ where: { sub: sub.decoded } })
return {
...user,
+ roles: ['admin'],
}
}
- export const requireAuth = () => {
+ export const requireAuth = ({ roles } = { roles: [] }) => {
if (!context.currentUser) {
throw new AuthenticationError("You are not authenticated")
}
+ // We now check that the current user's role matches!
+ if (!roles.some((role) => context.currentUser.roles.includes(role))) {
+ throw new AuthenticationError("You are not authenticated")
+ }
}
And invoke it in your services:
export const blogPosts = () => {
- requireAuth()
+ requireAuth({ roles: ['admin'] })
// fetch blogPosts...
}
On the web side we’ve introduced a new hasRole
hook:
const { isAuthenticated, hasRole } = useAuth()
{hasRole('admin') && (
<Link to={routes.admin()}>Admin</Link>
)}
And a way to protect routes by role:
<Router>
<Private unauthenticated="forbidden" role="admin">
<Route path="/settings" page={SettingsPage} name="settings" />
<Route path="/admin" page={AdminPage} name="sites" />
</Private>
<Route path="/forbidden" page={ForbiddenPage} name="forbidden" />
</Router>
Check out the auth documentation for more information
Changed
- Prisma upgraded to v2.4.0, @peterp #937
- We switched our Date, Time, and JSON scalar types to graphQL scalar library, @hemildesai #918
- Add stub types to @redwoodjs/forms, @Burnsy #922
- Disable SDL parameter type checking, @aldonline #944
- Warn instead of error on prettier linting errors, @turadg #952
Added
- Added roles to
@redwoodjs/auth
, @dthyresson #939 - A way to generate pages with route parameters, doing
yarn rw g page post {id}
will now add the parameter to the route’s path and page component. @Tobbe #882 - Added the webpack-retry-chunks plugin, @dac09 #929
- Add descriptions to
yarn rw test
command, @forresthayes #950
Fixed
- Fixed a bug in the GraphQLClientConfig of the GraphQLAuthProvider, @hemildesai #931
- Fixed intermittent connection issues between webpack and dev-server proxy, @hemildesai #940
- Make data migration call
process.exit(1)
when failing, @MontelAle #948 - Remove the warning about production usage and Prisma, @amorriscode #958
- Add a proper way to remove history listeners @peterp #959
Breaking
ImportAll.macro removed
We deprecated importAll.macro
in v0.13.0, and now we’ve finally removed it. You’ll need to change your api/src/functions/graphql.js
file to the following:
import {
createGraphQLHandler,
makeMergedSchema,
makeServices,
} from '@redwoodjs/api'
-import importAll from '@redwoodjs/api/importAll.macro'
-const schemas = importAll('api', 'graphql')
-const services = importAll('api', 'services')
+import schemas from 'src/graphql/**/*.{js,ts}'
+import services from 'src/services/**/*.{js,ts}'
import { db } from 'src/lib/db'
export const handler = createGraphQLHandler({
schema: makeMergedSchema({
schemas,
services: makeServices({ services }),
}),
db,
})
How to upgrade RedwoodJS to v0.16.0
- Check out the breaking changes to
importAll.macro
. - Our Prisma Dynamic Plugin Provider is no longer required:
Remove it from package.json
"devDependencies": { - "netlify-plugin-prisma-provider": "^0.3.0" },
Remove it from netlify.toml
- [[plugins]]
- package = 'netlify-plugin-prisma-provider'
- [plugins.inputs]
- path = 'api/prisma/schema.prisma'
You must run yarn rw db save
to create a new migration.
If you’re stuck please ask for help on our community, or read the deployment docs
IMPORTANT: Skipping versions when upgrading is not recommended and will likely cause problems. Do read through all Release Notes between your current version and this latest version. Each minor release will likely require you to implement breaking change fixes and apply manual code modifications.
Upgrade Packages
Run the following command within your App directory:
yarn rw upgrade
To run the upgrade
command, your project must be using v0.6.0 or greater. See this forum topic for manual upgrade instructions and general upgrade help.
Redwood Releases on GitHub
You can see all Redwood release notes and version history on GitHub