Skip to content

Commit

Permalink
feat: 🚀 add next password protect (#79)
Browse files Browse the repository at this point in the history
Co-authored-by: Maren Osnabrug <[email protected]>
Co-authored-by: MitchelvanBever <[email protected]>
  • Loading branch information
3 people authored Sep 20, 2021
1 parent 097d687 commit d88d923
Show file tree
Hide file tree
Showing 6 changed files with 265 additions and 201 deletions.
2 changes: 2 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ module.exports = withBundleAnalyzer(
// marked for the release they belong to. It may be undefined if running
// outside of Vercel
NEXT_PUBLIC_COMMIT_SHA: CI_COMMIT_SHA,
// Protect staging with a password
PASSWORD_PROTECT: process.env.NEXT_PUBLIC_ENVIRONMENT === 'staging',
},
webpack(config, options) {
config.resolve.plugins = [
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@sentry/integrations": "6.9.0",
"@sentry/node": "6.9.0",
"@storyofams/next-api-decorators": "1.5.5",
"@storyofams/next-password-protect": "^1.5.8",
"@storyofams/react-helpers": "0.3.8",
"@storyofams/react-ui": "1.2.0",
"@styled-system/css": "5.1.5",
Expand Down
23 changes: 12 additions & 11 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { withPasswordProtect } from '@storyofams/next-password-protect';
import { DefaultSeo } from 'next-seo';
import { AppProps } from 'next/app';
import { ReactQueryDevtools } from 'react-query/devtools';
Expand All @@ -13,15 +14,15 @@ if (process.env.NEXT_PUBLIC_SENTRY_DSN) {
initSentry();
}

const MyApp = ({ pageProps, Component }: AppProps) => {
return (
<Providers pageProps={pageProps}>
<CSSreset />
<DefaultSeo {...seo} />
<Component {...pageProps} />
<ReactQueryDevtools initialIsOpen={false} />
</Providers>
);
};
const MyApp = ({ pageProps, Component }: AppProps) => (
<Providers pageProps={pageProps}>
<CSSreset />
<DefaultSeo {...seo} />
<Component {...pageProps} />
<ReactQueryDevtools initialIsOpen={false} />
</Providers>
);

export default MyApp;
export default process.env.PASSWORD_PROTECT
? withPasswordProtect(MyApp)
: MyApp;
5 changes: 5 additions & 0 deletions src/pages/api/login.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { loginHandler } from '@storyofams/next-password-protect';

export default loginHandler(process.env.STAGING_PASSWORD, {
cookieSameSite: 'none',
});
3 changes: 3 additions & 0 deletions src/pages/api/passwordCheck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { passwordCheckHandler } from '@storyofams/next-password-protect';

export default passwordCheckHandler(process.env.STAGING_PASSWORD);
Loading

1 comment on commit d88d923

@vercel
Copy link

@vercel vercel bot commented on d88d923 Sep 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.