Skip to content

Commit 044f1df

Browse files
authored
Merge branch 'main' into signup
2 parents 1f4e710 + c6d36eb commit 044f1df

File tree

13 files changed

+124
-23
lines changed

13 files changed

+124
-23
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ VITE_SUPABASE_URL=
22
VITE_SUPABASE_ANON_KEY=
33
VITE_NCU_PORTAL_CLIENT_ID=
44
VITE_NCU_PORTAL_CLIENT_SECRET=
5+
VITE_ROOT_PATH=http://localhost:5173
6+
VITE_SERVER_PATH=http://localhost:3000

.github/workflows/vite-gh-pages.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,18 @@ jobs:
3737
echo "VITE_SUPABASE_ANON_KEY=${{ secrets.VITE_SUPABASE_ANON_KEY }}" >> .env
3838
echo "VITE_NCU_PORTAL_CLIENT_ID=${{ secrets.VITE_NCU_PORTAL_CLIENT_ID }}" >> .env
3939
echo "VITE_NCU_PORTAL_SECRET=${{ secrets.VITE_NCU_PORTAL_SECRET }}" >> .env
40+
echo "VITE_ROOT_PATH=${{ secrets.VITE_ROOT_PATH }}" >> .env
41+
echo "VITE_SERVER_PATH=${{ secrets.VITE_SERVER_PATH }}" >> .env
42+
4043
env:
4144
VITE_SUPABASE_URL: ${{ secrets.VITE_SUPABASE_URL }}
4245
VITE_SUPABASE_ANON_KEY: ${{ secrets.VITE_SUPABASE_ANON_KEY }}
4346
VITE_NCU_PORTAL_CLIENT_ID: ${{ secrets.VITE_NCU_PORTAL_CLIENT_ID }}
4447
VITE_NCU_PORTAL_SECRET: ${{ secrets.VITE_NCU_PORTAL_SECRET }}
48+
VITE_ROOT_PATH: ${{ secrets.VITE_ROOT_PATH }}
49+
VITE_SERVER_PATH: $ {{ secrets.VITE_SERVER_PATH }}
4550

4651

47-
4852
# Debug - Verify .env file creation
4953
- name: Debug - Verify .env file creation
5054
run: |

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ dev-dist
2727
/playwright-report/
2828
/blob-report/
2929
/playwright/.cache/
30+
/.github/workflows/vite-gh-pages.yml

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ VITE_NCU_PORTAL_CLIENT_ID=
8989
VITE_NCU_PORTAL_CLIENT_SECRET=
9090
```
9191

92+
複製`.env.example`的最後兩行至`.env`
93+
```
94+
VITE_ROOT_PATH=http://localhost:5173
95+
VITE_SERVER_PATH=http://localhost:3000
96+
```
97+
9298

9399
### Edge Functions
94100

src/backend/auth/server.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ dotenv.config();
77

88
const app = express();
99
app.use(cors({
10-
origin: "http://localhost:5173",
10+
origin: process.env.VITE_ROOT_PATH,
1111
credentials: true
1212
}));
1313
app.use(express.json());
1414
app.use(express.urlencoded({ extended: true }));
1515

1616
const CLIENT_ID = process.env.VITE_NCU_PORTAL_CLIENT_ID;
1717
const CLIENT_SECRET = process.env.VITE_NCU_PORTAL_CLIENT_SECRET;
18-
const REDIRECT_URI = "http://localhost:5173/callback";
18+
const REDIRECT_URI = `${process.env.VITE_ROOT_PATH}/callback`;
1919

2020
app.post('/oauth2/token', async (req, res) => {
2121
// console.log("Received request body:", req.body); // Debugging log
@@ -90,5 +90,5 @@ app.get('/oauth2/userinfo', async (req, res) => {
9090

9191

9292
app.listen(3000, () => {
93-
console.log("OAuth server running on http://localhost:3000");
93+
console.log("OAuth server running...");
9494
});

src/components/pages/home/Header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const Header: React.FC = () => {
4141
}, []);
4242

4343
if (!userName || !userAvatar) {
44-
return <div>Loading...</div>;
44+
return null;
4545
}
4646
if (error) {
4747
console.log('error', error);

src/routes/__root.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
import { createRootRoute, Outlet, useMatchRoute } from '@tanstack/react-router';
1+
import { createRootRoute, Outlet } from '@tanstack/react-router';
22
import { Header } from '../components/pages/home/Header';
33

44
export const Route = createRootRoute({
55
component: RootComponent,
66
});
77

88
function RootComponent() {
9-
const match = useMatchRoute();
109

1110
return (
1211
<div className='w-full lg:w-2/3 mx-auto flex flex-col lg:flex-row justify-center'>
13-
{match({ to: '/login' }) ? null : <Header />}
12+
<Header />
1413
<Outlet />
1514
</div>
1615
);

src/routes/callback.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ export const Route = createFileRoute('/callback')({
55
component: Callback,
66
})
77

8+
const rootPath = import.meta.env.VITE_ROOT_PATH;
9+
const serverPath = import.meta.env.VITE_SERVER_PATH;
10+
811
function Callback() {
912
const navigate = useNavigate();
1013

@@ -21,7 +24,7 @@ function Callback() {
2124

2225
try {
2326
// 交換 access_token
24-
const tokenResponse = await fetch('http://localhost:3000/oauth2/token', {
27+
const tokenResponse = await fetch(`${serverPath}/oauth2/token`, {
2528
method: 'POST',
2629
headers: {
2730
'Accept': 'application/json',
@@ -31,7 +34,7 @@ function Callback() {
3134
code,
3235
client_id: import.meta.env.VITE_NCU_PORTAL_CLIENT_ID,
3336
client_secret: import.meta.env.VITE_NCU_PORTAL_CLIENT_SECRET,
34-
redirect_uri: 'http://localhost:5173/callback',
37+
redirect_uri: `${rootPath}/callback`,
3538
grant_type: 'authorization_code'
3639
})
3740
});
@@ -44,7 +47,7 @@ function Callback() {
4447
}
4548

4649
// 取得使用者資訊
47-
const userResponse = await fetch('http://localhost:3000/oauth2/userinfo', {
50+
const userResponse = await fetch(`${serverPath}/oauth2/userinfo`, {
4851
method: 'GET',
4952
headers: {
5053
'Authorization': `Bearer ${tokenData.access_token}`,

src/routes/login.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ function LoginPage() {
2121
const { redirect: redirectUrl } = Route.useSearch()
2222

2323
const CLIENT_ID = import.meta.env.VITE_NCU_PORTAL_CLIENT_ID;
24+
const rootPath = import.meta.env.VITE_ROOT_PATH;
2425

25-
const REDIRECT_URI = 'http://localhost:5173/callback';
26+
const REDIRECT_URI = `${rootPath}/callback`;
2627
const supportedURL = 'https://github.com/NCUAppTeam/Legacy-website./blob/main/PRIVACY.md'
2728

2829

src/routes/signup.tsx

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createFileRoute, useNavigate, useRouterState } from '@tanstack/react-router';
2-
import { useEffect, useState } from 'react';
2+
import { useEffect, useRef, useState } from 'react';
33
import zxcvbn from 'zxcvbn'; //記得要先安裝zxcvbn,輸入 npm install zxcvbn
44
import UserController from '../backend/user/Controllers/UserController';
55
import UserSignupData from '../backend/user/Entities/UserSignupData';
@@ -11,6 +11,7 @@ function SignUpPage() {
1111
const navigate = useNavigate();
1212
const state = useRouterState({ select: (s) => s.location.state })
1313
const [userData, setUserData] = useState<UserInfo>()
14+
1415
useEffect(() => {
1516
if (!state.post?.userData) {
1617
navigate({ to: '/' })
@@ -46,6 +47,7 @@ function SignUpForm({ userInfo, navigate }: { userInfo: UserInfo; navigate: Retu
4647
nickname: '',
4748
password: '',
4849
})
50+
const passwordCRef = useRef<HTMLInputElement>(null);
4951

5052
const [passwordStrength, setPasswordStrength] = useState(0)
5153

@@ -95,6 +97,11 @@ function SignUpForm({ userInfo, navigate }: { userInfo: UserInfo; navigate: Retu
9597
return
9698
}
9799

100+
if (passwordCRef.current && passwordCRef.current.value !== formData.password) {
101+
alert('兩次輸入的密碼不一致');
102+
return;
103+
}
104+
98105
console.log('Submitted Data:', {
99106
nickname: trimmedNickname,
100107
password: formData.password,
@@ -227,7 +234,6 @@ function SignUpForm({ userInfo, navigate }: { userInfo: UserInfo; navigate: Retu
227234
id="nickname"
228235
value={formData.nickname}
229236
onChange={handleChange}
230-
required
231237
className="mt-2 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-600 focus:ring-indigo-600 sm:text-sm"
232238
placeholder="Enter your nickname"
233239
/>
@@ -249,12 +255,27 @@ function SignUpForm({ userInfo, navigate }: { userInfo: UserInfo; navigate: Retu
249255
handleChange(e)
250256
passwordCheck(e)
251257
}}
252-
required
253258
className="mt-2 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-600 focus:ring-indigo-600 sm:text-sm"
254259
placeholder="Enter your password"
255260
/>
256261
</div>
257-
262+
263+
<div>
264+
<label
265+
htmlFor="passwordC"
266+
className="block text-sm font-medium text-gray-900"
267+
>
268+
確認密碼
269+
</label>
270+
<input
271+
type="password"
272+
ref={passwordCRef}
273+
id="passwordC"
274+
className="mt-2 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-600 focus:ring-indigo-600 sm:text-sm"
275+
placeholder="Enter your password again"
276+
/>
277+
</div>
278+
258279
<div className="mt-2 w-full h-3 bg-gray-200 rounded-full">
259280
<div
260281
className={`h-full rounded-full ${strengthColors[passwordStrength]}`}

0 commit comments

Comments
 (0)