Skip to content

Commit a25d62b

Browse files
authored
feat: auth for dev (#29)
* feat: auth for dev * fix EOL * deploy test * fix: favicon link * restore test * fix: use password hash * remove unused condition
1 parent 913ad4b commit a25d62b

File tree

16 files changed

+78
-31
lines changed

16 files changed

+78
-31
lines changed

.env.tmpl

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
NEXT_PUBLIC_AUTH_PASSWORD_HASH="password_hashed_via_sha256"

.github/workflows/ci.yml

+9-6
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,18 @@ jobs:
1616
uses: actions/setup-node@v3
1717
with:
1818
node-version: ${{ matrix.node-version }}
19+
- name: create .env file
20+
run: |
21+
echo "${{ secrets.ENV }}" > .env
1922
- name: install deps
2023
run: yarn
2124
- name: lint
2225
run: yarn lint
2326
- name: build
2427
run: yarn build
25-
# - name: Deploy
26-
# uses: peaceiris/actions-gh-pages@v3
27-
# if: github.ref == 'refs/heads/main'
28-
# with:
29-
# github_token: ${{ secrets.GITHUB_TOKEN }}
30-
# publish_dir: ./out
28+
- name: Deploy
29+
uses: peaceiris/actions-gh-pages@v3
30+
if: github.ref == 'refs/heads/main'
31+
with:
32+
github_token: ${{ secrets.GITHUB_TOKEN }}
33+
publish_dir: ./out

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ yarn-error.log*
2727

2828
# local env files
2929
.env*.local
30+
.env
3031

3132
# vercel
3233
.vercel

README.md

+10-15
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,18 @@ yarn dev
1313

1414
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
1515

16-
You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file.
16+
## storybook
1717

18-
[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`.
19-
20-
The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.
21-
22-
## Learn More
23-
24-
To learn more about Next.js, take a look at the following resources:
25-
26-
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
27-
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
18+
```bash
19+
yarn storybook
20+
```
2821

29-
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
22+
## deploy
3023

31-
## Deploy on Vercel
24+
Auto-deploy runs when merged into main.
3225

33-
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
26+
if GitHub secrets `ENV` is set as below, password lock is enabled.
3427

35-
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
28+
```
29+
NEXT_PUBLIC_AUTH_PASSWORD="password"
30+
```

next.config.js

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
const nextConfig = {
33
reactStrictMode: true,
44
swcMinify: true,
5+
assetPrefix: '/2023/',
6+
basePath: '/2023',
7+
trailingSlash: true,
8+
exportPathMap: async function () {
9+
return {
10+
"/": { page: "/" }
11+
}
12+
},
513
}
614

715
module.exports = nextConfig

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"next": "12.3.1",
2121
"react": "18.2.0",
2222
"react-dom": "18.2.0",
23-
"react-i18next": "11.18.6"
23+
"react-i18next": "11.18.6",
24+
"use-local-storage-state": "18.1.1"
2425
},
2526
"devDependencies": {
2627
"@babel/core": "7.19.3",

src/components/commons/Layout/index.tsx

+31-2
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,50 @@
11
import type { NextPage } from 'next'
22
import { ReactNode } from 'react'
33
import Head from 'next/head'
4+
45
import { Header } from 'src/components/organisms'
56
import { Footer } from 'src/components/organisms'
6-
import { Box } from '@mui/material'
7+
import { toSha256 } from 'src/modules/util/hash'
8+
9+
import { Box, Input } from '@mui/material'
10+
import useLocalStorageState from 'use-local-storage-state'
711

812
export interface LayoutProps {
913
children: ReactNode
1014
}
1115

1216
export const Layout: NextPage<LayoutProps> = ({ children }) => {
17+
const config = require('../../../../next.config')
18+
const [authorized, setAuthorized] = useLocalStorageState('authorized', { defaultValue: false })
19+
20+
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
21+
if (toSha256(e.target.value) === process.env.NEXT_PUBLIC_AUTH_PASSWORD_HASH) setAuthorized(true)
22+
}
23+
24+
if (process.env.NEXT_PUBLIC_AUTH_PASSWORD_HASH && !authorized)
25+
return (
26+
<Box
27+
sx={{
28+
width: '100vw',
29+
height: '100vh',
30+
display: 'flex',
31+
alignItems: 'center',
32+
justifyContent: 'center'
33+
}}
34+
>
35+
<Box>
36+
<Input onChange={handleChange} placeholder="enter password" />
37+
</Box>
38+
</Box>
39+
)
40+
1341
return (
1442
<>
1543
<Head>
1644
<title>Go Conference 2023</title>
45+
<base href={config.basePath + '/'} />
1746
<meta name="description" content="Go Conference is a half-annual conference of programming language Go." />
18-
<link rel="icon" href="/favicon.ico" />
47+
<link rel="icon" href="./favicon.ico" />
1948
</Head>
2049
<Box>
2150
<Header />

src/components/organisms/Footer/FooterBottom.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Box } from '@mui/material'
2-
import { useSize } from 'src/modules/common/hooks'
2+
import { useSize } from 'src/modules/hooks'
33

44
interface FooterBottomProps {
55
children: React.ReactNode

src/components/organisms/Footer/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Box, Typography } from '@mui/material'
22
import { Colors } from 'src/styles/color'
33
import { useTranslation } from 'react-i18next'
4-
import { useSize } from 'src/modules/common/hooks'
4+
import { useSize } from 'src/modules/hooks'
55
import { FooterBottom } from 'src/components/organisms/Footer/FooterBottom'
66
import { IconTwitter, Link } from 'src/components/atoms'
77

src/components/organisms/Header/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { AppBar, Toolbar, Typography, Box } from '@mui/material'
44
import { Colors } from 'src/styles/color'
55
import { useTranslation } from 'react-i18next'
66
import { Logo } from 'src/components/atoms'
7-
import { useScrollY } from 'src/modules/common/hooks'
7+
import { useScrollY } from 'src/modules/hooks'
88

99
const handleChangeLanguage = () => {
1010
switch (i18n.language) {

src/components/organisms/MainVisual/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Box, Container, Typography } from '@mui/material'
22
import { Colors } from 'src/styles/color'
3-
import { useSize } from 'src/modules/common/hooks'
3+
import { useSize } from 'src/modules/hooks'
44
import Image from 'next/image'
55

66
export const MainVisual = () => {
77
const { isTabletOrOver } = useSize()
8-
const image_path = isTabletOrOver ? '/Background-pc.png' : '/Background-sp.png'
8+
const image_path = isTabletOrOver ? './Background-pc.png' : './Background-sp.png'
99

1010
return (
1111
<Box>

src/components/organisms/TopDescription/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Box, Typography } from '@mui/material'
22
import { Colors } from 'src/styles/color'
3-
import { useSize } from 'src/modules/common/hooks'
3+
import { useSize } from 'src/modules/hooks'
44
import { useTranslation } from 'react-i18next'
55

66
export const TopDescription = () => {

src/components/pages/PageTop/index.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export const PageTop: NextPage = () => {
1111

1212
return (
1313
<Layout>
14-
implement later
1514
<MainVisual />
1615
<TopDescription />
1716
<Typography variant="h2">Wanted to Speakers!</Typography>
File renamed without changes.

src/modules/util/hash.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const { createHash } = require('crypto')
2+
3+
export function toSha256(s: string) {
4+
return createHash('sha256').update(s).digest('hex')
5+
}

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -11438,6 +11438,11 @@ url@^0.11.0:
1143811438
punycode "1.3.2"
1143911439
querystring "0.2.0"
1144011440

11441+
use-local-storage-state@^18.1.1:
11442+
version "18.1.1"
11443+
resolved "https://registry.yarnpkg.com/use-local-storage-state/-/use-local-storage-state-18.1.1.tgz#40e535aebed7770258e0a3a7b6923a86d9c0c52f"
11444+
integrity sha512-09bl6q3mkSlkEt8KeBPCmdPEWEojWYF70Qbz+7wkfQX1feaFITM9m84+h0Jr6Cnf/IvpahkFh7UbX2VNN3ioTQ==
11445+
1144111446
1144211447
version "1.2.0"
1144311448
resolved "https://registry.yarnpkg.com/use-sync-external-store/-/use-sync-external-store-1.2.0.tgz#7dbefd6ef3fe4e767a0cf5d7287aacfb5846928a"

0 commit comments

Comments
 (0)