-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from hammerframework/pp-add-auth0
Use Auth0 for authentication.
- Loading branch information
Showing
23 changed files
with
960 additions
and
117 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -3,6 +3,7 @@ dist | |
yarn-error.log | ||
.docz | ||
*/.env | ||
.env | ||
.DS_Store | ||
|
||
api/failed-*.md | ||
|
This file contains 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 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 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,5 @@ | ||
import { graphQLServerlessFunction } from "@hammerframework/hammer-api"; | ||
|
||
export const SERVERLESS_FUNCTION_TYPE = "aws"; | ||
|
||
export const handler = graphQLServerlessFunction(); |
This file contains 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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// // https://www.netlify.com/blog/2018/09/13/how-to-run-express.js-apps-with-netlify-functions/ | ||
// // https://github.com/dougmoscrop/serverless-http | ||
|
||
import jwt from "express-jwt"; | ||
import jwksRsa from "jwks-rsa"; | ||
|
||
import dotenv from "dotenv"; | ||
|
||
// hammer base dir. | ||
dotenv.config("../../.env"); | ||
|
||
// Set up Auth0 configuration | ||
const authConfig = { | ||
domain: process.env.AUTH0_DOMAIN, | ||
audience: process.env.AUTH0_AUDIENCE | ||
}; | ||
|
||
// Define middleware that validates incoming bearer tokens | ||
// using JWKS from p4p8.eu.auth0.com | ||
const checkJwt = jwt({ | ||
secret: jwksRsa.expressJwtSecret({ | ||
cache: true, | ||
rateLimit: true, | ||
jwksRequestsPerMinute: 5, | ||
jwksUri: `https://${authConfig.domain}/.well-known/jwks.json` | ||
}), | ||
|
||
audience: authConfig.audience, | ||
issuer: `https://${authConfig.domain}/`, | ||
algorithm: ["RS256"] | ||
}); | ||
|
||
export const SERVERLESS_FUNCTION_TYPE = "express"; | ||
|
||
export const handler = (req, res, next) => { | ||
checkJwt(req, res, next); | ||
|
||
res.send({ | ||
msg: "Your Access Token was successfully validated!" | ||
}); | ||
}; |
This file contains 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 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 |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
] | ||
], | ||
"plugins": [ | ||
"@babel/plugin-transform-runtime", | ||
[ | ||
"babel-plugin-module-resolver", | ||
{ | ||
|
This file contains 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 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 was deleted.
Oops, something went wrong.
This file contains 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,23 +1,49 @@ | ||
import { Box } from "src/lib/primitives"; | ||
import { Flex, Box, Button } from "src/lib/primitives"; | ||
import { useAuth0 } from "src/lib/auth0"; | ||
import { Link } from "react-router-dom"; | ||
|
||
export default () => ( | ||
<Box | ||
bg="blue" | ||
css={` | ||
height: 64px; | ||
`} | ||
> | ||
export default () => { | ||
const { isAuthenticated, loginWithRedirect, logout } = useAuth0(); | ||
|
||
return ( | ||
<Box | ||
color="white" | ||
fontSize={5} | ||
pl="8px" | ||
m="auto" | ||
bg="blue" | ||
css={` | ||
width: 800px; | ||
line-height: 64px; | ||
height: 64px; | ||
`} | ||
> | ||
Billable | ||
<Flex | ||
flexDirection="row" | ||
color="white" | ||
fontSize={5} | ||
pl="8px" | ||
m="auto" | ||
css={` | ||
width: 800px; | ||
line-height: 64px; | ||
`} | ||
> | ||
Billable | ||
<Box | ||
ml="auto" | ||
css={` | ||
display: flex; | ||
align-items: center; | ||
`} | ||
> | ||
{!isAuthenticated && ( | ||
<> | ||
<Button onClick={() => loginWithRedirect({})}>Log in</Button> | ||
<Button onClick={() => loginWithRedirect({})}>Sign up</Button> | ||
</> | ||
)} | ||
{isAuthenticated && ( | ||
<> | ||
<Button onClick={() => logout()}>Log out</Button> | ||
</> | ||
)} | ||
</Box> | ||
</Flex> | ||
</Box> | ||
</Box> | ||
); | ||
); | ||
}; |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import ReactDOM from "react-dom"; | ||
import { GraphQLProvider } from "@hammerframework/hammer-web"; | ||
import { ThemeProvider } from "styled-components"; | ||
|
||
import { Auth0Provider } from "src/lib/auth0"; | ||
|
||
import theme from "src/lib/theme"; | ||
import Routes from "src/pages/Routes"; | ||
|
||
import "./index.css"; | ||
|
||
ReactDOM.render( | ||
<GraphQLProvider> | ||
<ThemeProvider theme={theme}> | ||
<Auth0Provider | ||
config={{ | ||
domain: process.env.AUTH0_DOMAIN, | ||
client_id: process.env.AUTH0_CLIENT_ID, | ||
audience: process.env.AUDIENCE, | ||
redirect_uri: window.location.origin | ||
}} | ||
> | ||
<Routes /> | ||
</Auth0Provider> | ||
</ThemeProvider> | ||
</GraphQLProvider>, | ||
document.getElementById("hammer-app") | ||
); |
Oops, something went wrong.