Skip to content

Commit

Permalink
Merge branch 'main' into fix/use-fresh-tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
dac09 authored Jan 21, 2021
2 parents 3a11c79 + ce645a6 commit 439044d
Show file tree
Hide file tree
Showing 109 changed files with 16,366 additions and 273 deletions.
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
dist
fixtures
packages/api/importAll.macro.js
packages/core/**/__fixtures__/**/*
packages/core/config/storybook/**/*
26 changes: 25 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "@redwoodjs/eslint-config",
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"import/order": [
"error",
{
Expand Down Expand Up @@ -36,5 +37,28 @@
}
}
]
}
},
"overrides": [
{
"files": [
"**/template/web/src/Routes.js"
],
"rules": {
"no-undef": "off"
}
},
{
"files": [
"packages/structure/**"
],
"rules": {
"@typescript-eslint/no-this-alias": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"no-case-declarations": "off",
"prefer-const": "off",
"no-empty": "warn",
"no-unused-expressions": "off"
}
}
]
}
9 changes: 7 additions & 2 deletions .github/workflows/publish_pr_packages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,16 @@ jobs:
pr_number=${{ steps.pr_number.outputs.pr_number }}
cd pr-packages/$pr_number
v_sha=$(ls | grep "\.tgz$" | sed 's/\.tgz$//' | head -n1 | awk -F"-" '{ print $(NF-1)"-"$NF }')
msg="📦 Packages for this PR can be downloaded from%0A"
msg="### 📦 PR Packages%0A"
msg+="%0A"
msg+="<details><summary>Click to Show Package Download Links</summary>%0A"
msg+="%0A"
for p in *; do
msg+="https://rw-pr-redwoodjs-com.s3.amazonaws.com/$pr_number/$p%0A"
done
msg+="%0AInstall this PR by running \`yarn rw upgrade --pr $pr_number:$v_sha\`"
msg+="</details>%0A"
msg+="%0A"
msg+="Install this PR by running \`yarn rw upgrade --pr $pr_number:$v_sha\`"
echo "::set-output name=msg::$msg"
- name: Find Comment
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,19 @@ And there you have it.
<tr>
<td align="center"><a href="https://github.com/Chuloo"><img src="https://avatars3.githubusercontent.com/u/22301208?v=4" width="100px;" alt=""/><br /><sub><b>William</b></sub></a></td>
<td align="center"><a href="https://github.com/dcgoodwin2112"><img src="https://avatars1.githubusercontent.com/u/4554388?v=4" width="100px;" alt=""/><br /><sub><b>dcgoodwin2112</b></sub></a></td>
<td align="center"><a href="https://github.com/bennettrogers"><img src="https://avatars1.githubusercontent.com/u/933251?v=4" width="100px;" alt=""/><br /><sub><b>Bennett Rogers</b></sub></a></td>
<td align="center"><a href="https://github.com/byudaniel"><img src="https://avatars0.githubusercontent.com/u/7226285?v=4" width="100px;" alt=""/><br /><sub><b>Daniel O'Neill</b></sub></a></td>
<td align="center"><a href="https://github.com/noobling"><img src="https://avatars2.githubusercontent.com/u/23206864?v=4" width="100px;" alt=""/><br /><sub><b>David Yu</b></sub></a></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/adithyasunil26"><img src="https://avatars0.githubusercontent.com/u/51863389?v=4" width="100px;" alt=""/><br /><sub><b>Adithya Sunil</b></sub></a></td>
<td align="center"><a href="https://edjiang.com/"><img src="https://avatars1.githubusercontent.com/u/918770?v=4" width="100px;" alt=""/><br /><sub><b>Edward Jiang</b></sub></a></td>
<td align="center"><a href="http://manukall.de/"><img src="https://avatars0.githubusercontent.com/u/117418?v=4" width="100px;" alt=""/><br /><sub><b>Manuel Kallenbach</b></sub></a></td>
<td align="center"><a href="https://github.com/NickSchmitt"><img src="https://avatars3.githubusercontent.com/u/23244885?v=4" width="100px;" alt=""/><br /><sub><b>Nick Schmitt</b></sub></a></td>
<td align="center"><a href="https://monoglot.dev/"><img src="https://avatars0.githubusercontent.com/u/13792200?v=4" width="100px;" alt=""/><br /><sub><b>Jon Meyers</b></sub></a></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/mbush92"><img src="https://avatars0.githubusercontent.com/u/15862774?v=4" width="100px;" alt=""/><br /><sub><b>Matthew Bush</b></sub></a></td>
</tr>
</table>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => 'I am a TypeScript page.'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => 'I am an page in a subdirectory.'
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.22.1",
"version": "0.23.0",
"npmClient": "yarn",
"useWorkspaces": true,
"command": {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"build:clean": "rimraf ./packages/**/dist",
"build:watch": "ttsc --build && lerna run build:watch --parallel",
"test": "lerna run test --stream -- --colors --maxWorkers=4",
"lint": "eslint packages",
"lint:fix": "eslint --fix packages"
"lint": "eslint -c .eslintrc packages",
"lint:fix": "eslint -c .eslintrc --fix packages"
},
"private": true,
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/api-server/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@redwoodjs/api-server",
"description": "Redwood's HTTP server for Serverless Functions",
"version": "0.22.1",
"version": "0.23.0",
"bin": {
"api-server": "./dist/index.js"
},
Expand Down
8 changes: 4 additions & 4 deletions packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@redwoodjs/api",
"version": "0.22.1",
"version": "0.23.0",
"files": [
"dist"
],
Expand All @@ -9,7 +9,7 @@
"license": "MIT",
"dependencies": {
"@prisma/client": "2.12.1",
"@redwoodjs/internal": "^0.22.1",
"@redwoodjs/internal": "^0.23.0",
"apollo-server-lambda": "2.18.2",
"core-js": "3.6.5",
"graphql": "^15.3.0",
Expand All @@ -22,8 +22,8 @@
"merge-graphql-schemas": "^1.7.6"
},
"devDependencies": {
"@redwoodjs/auth": "^0.22.1",
"@redwoodjs/dev-server": "^0.22.1",
"@redwoodjs/auth": "^0.23.0",
"@redwoodjs/dev-server": "^0.23.0",
"@types/jsonwebtoken": "^8.3.9",
"@types/lodash.merge": "^4.6.6",
"@types/lodash.omitby": "^4.6.6"
Expand Down
15 changes: 15 additions & 0 deletions packages/api/src/auth/decoders/ethereum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import jwt from 'jsonwebtoken'

export const ethereum = (token: string) => {
if (!process.env.ETHEREUM_JWT_SECRET) {
console.error('ETHEREUM_JWT_SECRET env var is not set.')
throw new Error('ETHEREUM_JWT_SECRET env var is not set.')
}

try {
const secret = process.env.ETHEREUM_JWT_SECRET as string
return Promise.resolve(jwt.verify(token, secret) as Record<string, unknown>)
} catch (error) {
return Promise.reject(error)
}
}
2 changes: 2 additions & 0 deletions packages/api/src/auth/decoders/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { GlobalContext } from 'src/globalContext'

import { auth0 } from './auth0'
import { azureActiveDirectory } from './azureActiveDirectory'
import { ethereum } from './ethereum'
import { netlify } from './netlify'
import { supabase } from './supabase'
const noop = (token: string) => token
Expand All @@ -29,6 +30,7 @@ const typesToDecoders: Record<
magicLink: noop,
firebase: noop,
supabase: supabase,
ethereum: ethereum,
custom: noop,
}

Expand Down
18 changes: 11 additions & 7 deletions packages/api/src/auth/decoders/netlify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ type NetlifyContext = ClientContext & {
}

export const netlify = (token: string, req: { context: LambdaContext }) => {
// Netlify verifies and decodes the JWT before the request is passed to our Serverless
// function, so the decoded JWT is already available in production.
if (process.env.NODE_ENV === 'production') {
// Netlify verifies and decodes the JWT before the request is passed to our
// Serverless function, so the decoded JWT is already available in production.
// For development and test we can't verify the token because we don't have
// the signing key. Just decoding the token is the best we can do to emulate
// the native Netlify experience
if (
process.env.NODE_ENV === 'development' ||
process.env.NODE_ENV === 'test'
) {
return jwt.decode(token)
} else {
const clientContext = req.context.clientContext as NetlifyContext
return clientContext?.user || null
} else {
// We emulate the native Netlify experience in development mode.
// We just decode it since we don't have the signing key.
return jwt.decode(token)
}
}
25 changes: 11 additions & 14 deletions packages/api/src/auth/decoders/supabase.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import jwt from 'jsonwebtoken'

export const supabase = (token: string) => {
if (process.env.NODE_ENV === 'production') {
if (!process.env.SUPABASE_JWT_SECRET) {
throw new Error('`SUPABASE_JWT_SECRET` env var is not set.')
}
if (!process.env.SUPABASE_JWT_SECRET) {
console.error('SUPABASE_JWT_SECRET env var is not set.')
throw new Error('SUPABASE_JWT_SECRET env var is not set.')
}

try {
const secret = process.env.SUPABASE_JWT_SECRET as string
return Promise.resolve(
jwt.verify(token, secret) as Record<string, unknown>
)
} catch (error) {
return Promise.reject(error)
}
} else {
return Promise.resolve(jwt.decode(token))
try {
const secret = process.env.SUPABASE_JWT_SECRET as string
return Promise.resolve(
jwt.verify(token, secret) as Record<string, unknown>
)
} catch (error) {
return Promise.reject(error)
}
}
2 changes: 1 addition & 1 deletion packages/api/src/functions/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const createGraphQLHandler = ({
onHealthCheck,
...options
}: GraphQLHandlerOptions = {}) => {
const isDevEnv = process.env.NODE_ENV !== 'production'
const isDevEnv = process.env.NODE_ENV === 'development'
const handler = new ApolloServer({
// Turn off playground, introspection and debug in production.
debug: isDevEnv,
Expand Down
1 change: 1 addition & 0 deletions packages/auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@ export type SupportedAuthClients =
| MagicLink
| Firebase
| Supabase
| Ethereum
| Custom
```
2 changes: 1 addition & 1 deletion packages/auth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@redwoodjs/auth",
"version": "0.22.1",
"version": "0.23.0",
"files": [
"dist"
],
Expand Down
28 changes: 28 additions & 0 deletions packages/auth/src/authClients/ethereum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export type EthereumUser = {
address: string | null
}

export type Ethereum = {
login(): Promise<any>
logout(): Promise<any>
getToken(): Promise<null | string>
getUserMetadata(): Promise<null | EthereumUser>
}

import type { AuthClient } from './'

export const ethereum = (client: Ethereum): AuthClient => {
return {
type: 'ethereum',
client,
login: async () => await client.login(),
signup: () => {
throw new Error(
`Ethereum auth does not support "signup". Please use "login" instead.`
)
},
logout: async () => await client.logout(),
getToken: async () => await client.getToken(),
getUserMetadata: async () => await client.getUserMetadata(),
}
}
18 changes: 4 additions & 14 deletions packages/auth/src/authClients/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,22 @@ export const firebase = (client: Firebase): AuthClient => {
type: 'firebase',
client,
restoreAuthState: () => client.auth().getRedirectResult(),
login: async (
withAuth: oAuthProvider | PasswordCreds = 'google.com'
) => {
login: async (withAuth: oAuthProvider | PasswordCreds = 'google.com') => {
if (isPasswordCreds(withAuth)) {
return client
.auth()
.signInWithEmailAndPassword(
withAuth.email,
withAuth.password
)
.signInWithEmailAndPassword(withAuth.email, withAuth.password)
}

const provider = getProvider(withAuth)
return client.auth().signInWithPopup(provider)
},
logout: () => client.auth().signOut(),
signup: async (
withAuth: oAuthProvider | PasswordCreds = 'google.com'
) => {
signup: async (withAuth: oAuthProvider | PasswordCreds = 'google.com') => {
if (isPasswordCreds(withAuth)) {
return client
.auth()
.createUserWithEmailAndPassword(
withAuth.email,
withAuth.password
)
.createUserWithEmailAndPassword(withAuth.email, withAuth.password)
}

const provider = getProvider(withAuth)
Expand Down
6 changes: 6 additions & 0 deletions packages/auth/src/authClients/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import type {
import { azureActiveDirectory } from './azureActiveDirectory'
import type { Custom } from './custom'
import { custom } from './custom'
import type { Ethereum, EthereumUser } from './ethereum'
import { ethereum } from './ethereum'
import type { Firebase } from './firebase'
import { firebase } from './firebase'
import type { GoTrue, GoTrueUser } from './goTrue'
Expand All @@ -26,6 +28,7 @@ const typesToClients = {
magicLink,
firebase,
supabase,
ethereum,
/** Don't we support your auth client? No problem, define your own the `custom` type! */
custom,
}
Expand All @@ -38,6 +41,7 @@ export type SupportedAuthClients =
| MagicLink
| Firebase
| Supabase
| Ethereum
| Custom

export type SupportedAuthTypes = keyof typeof typesToClients
Expand All @@ -47,12 +51,14 @@ export type { AzureActiveDirectoryUser }
export type { GoTrueUser }
export type { MagicUser }
export type { SupabaseUser }
export type { EthereumUser }
export type SupportedUserMetadata =
| Auth0User
| AzureActiveDirectoryUser
| GoTrueUser
| MagicUser
| SupabaseUser
| EthereumUser

export interface AuthClient {
restoreAuthState?(): void | Promise<any>
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@redwoodjs/cli",
"description": "The Redwood Command Line",
"version": "0.22.1",
"version": "0.23.0",
"license": "MIT",
"bin": {
"redwood": "./dist/index.js",
Expand All @@ -14,8 +14,8 @@
],
"dependencies": {
"@prisma/sdk": "2.12.1",
"@redwoodjs/internal": "^0.22.1",
"@redwoodjs/structure": "^0.22.1",
"@redwoodjs/internal": "^0.23.0",
"@redwoodjs/structure": "^0.23.0",
"boxen": "^4.2.0",
"camelcase": "^6.0.0",
"chalk": "^4.1.0",
Expand Down
Loading

0 comments on commit 439044d

Please sign in to comment.