Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix critical: update solid-js #120

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"remark-parse": "^10.0.2",
"remark-rehype": "^10.1.0",
"solid-emoji-picker": "^0.2.1",
"solid-js": "1.7.7",
"solid-js": "1.8.7",
"solid-transition-group": "^0.2.3",
"unified": "^10.1.2"
},
Expand Down
12 changes: 12 additions & 0 deletions src/pages/api/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { APIRoute } from 'astro'

const realPassword = import.meta.env.SITE_PASSWORD

export const post: APIRoute = async(context) => {
const body = await context.request.json()

const { pass } = body
return new Response(JSON.stringify({
code: (!realPassword || pass === realPassword) ? 0 : -1,
}))
}
20 changes: 20 additions & 0 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,23 @@ import BuildStores from '@/components/client-only/BuildStores'
<ModalsLayer client:only />
<BuildStores client:only />
</Layout>


<script>
async function checkCurrentAuth() {
const password = localStorage.getItem('pass')
const response = await fetch('/api/auth', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
pass: password,
}),
})
const responseJson = await response.json()
if (responseJson.code !== 0)
window.location.href = '/password'
}
checkCurrentAuth()
</script>
72 changes: 72 additions & 0 deletions src/pages/password.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
import Layout from '../layouts/Layout.astro'
---

<Layout title="Password Protection">
<main class="flex flex-col items-center justify-center h-screen">
<div class="op-30 text-2xl">
Please input password</div>
<div id="input_container" class="flex mt-4">
<input id="password_input" type="password" class="gpt-password-input" />
<div id="submit" class="gpt-password-submit">
<div class="i-carbon-arrow-right" />
</div>
</div>
</main>
</Layout>

<script>
const inputContainer = document.getElementById('input_container') as HTMLDivElement
const input = document.getElementById('password_input') as HTMLInputElement
const submitButton = document.getElementById('submit') as HTMLDivElement

input.onkeydown = async(event) => {
if (event.key === 'Enter')
handleSubmit()
}
submitButton.onclick = handleSubmit

async function handleSubmit() {
const password = input.value
const response = await fetch('/api/auth', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
pass: password,
}),
})
const responseJson = await response.json()
if (responseJson.code === 0) {
localStorage.setItem('pass', password)
window.location.href = '/'
} else {
inputContainer.classList.add('invalid')
setTimeout(() => {
inputContainer.classList.remove('invalid')
}, 300)
}
}
</script>

<style>
@keyframes shake {
0% {
transform: translateX(0);
}
25% {
transform: translateX(0.5rem);
}
75% {
transform: translateX(-0.5rem);
}
100% {
transform: translateX(0);
}
}

.invalid {
animation: shake 0.2s ease-in-out 0s 2;
}
</style>