Skip to content

Commit 4754d63

Browse files
authored
Merge pull request #3 from NCUAppTeam/deploy
Merge Deploy to Main
2 parents a7b87ae + 26a69c6 commit 4754d63

File tree

3 files changed

+80
-6
lines changed

3 files changed

+80
-6
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Deploy Vite with GitHub Pages dependencies preinstalled
2+
3+
on:
4+
# Runs on pushes targeting the default branch
5+
push:
6+
branches: ["main"]
7+
8+
# Allows you to run this workflow manually from the Actions tab
9+
workflow_dispatch:
10+
11+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
12+
permissions:
13+
contents: read
14+
pages: write
15+
id-token: write
16+
17+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
18+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
19+
concurrency:
20+
group: "pages"
21+
cancel-in-progress: false
22+
23+
jobs:
24+
# Build job
25+
build:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v4
30+
- name: Setup Pages
31+
uses: actions/configure-pages@v5
32+
33+
# Set up .env file with GitHub secrets
34+
- name: Set up .env with secrets
35+
run: |
36+
echo "VITE_SUPABASE_URL=${{ secrets.VITE_SUPABASE_URL }}" > .env
37+
echo "VITE_SUPABASE_ANON_KEY=${{ secrets.VITE_SUPABASE_ANON_KEY }}" >> .env
38+
echo "VITE_NCU_PORTAL_CLIENT_ID=${{ secrets.VITE_NCU_PORTAL_CLIENT_ID }}" >> .env
39+
echo "VITE_NCU_PORTAL_SECRET=${{ secrets.VITE_NCU_PORTAL_SECRET }}" >> .env
40+
env:
41+
VITE_SUPABASE_URL: ${{ secrets.VITE_SUPABASE_URL }}
42+
VITE_SUPABASE_ANON_KEY: ${{ secrets.VITE_SUPABASE_ANON_KEY }}
43+
VITE_NCU_PORTAL_CLIENT_ID: ${{ secrets.VITE_NCU_PORTAL_CLIENT_ID }}
44+
VITE_NCU_PORTAL_SECRET: ${{ secrets.VITE_NCU_PORTAL_SECRET }}
45+
46+
47+
48+
# Debug - Verify .env file creation
49+
- name: Debug - Verify .env file creation
50+
run: |
51+
if [ -f .env ]; then
52+
echo ".env file exists!"
53+
cat .env
54+
else
55+
echo ".env file does not exist!"
56+
fi
57+
58+
59+
- name: Build with Vite
60+
run: npm ci && npm run build
61+
- name: Upload artifact
62+
uses: actions/upload-pages-artifact@v3
63+
with:
64+
path: dist/
65+
# Deployment job
66+
deploy:
67+
environment:
68+
name: github-pages
69+
url: ${{ steps.deployment.outputs.page_url }}
70+
runs-on: ubuntu-latest
71+
needs: build
72+
steps:
73+
- name: Deploy to GitHub Pages
74+
id: deployment
75+
uses: actions/deploy-pages@v4

src/routes/callback.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function Callback() {
2121

2222
try {
2323
// 交換 access_token
24-
const tokenResponse = await fetch('http://localhost:3000/oauth2/token', {
24+
const tokenResponse = await fetch('https://ncuapp.davidday.tw/oauth2/token', {
2525
method: 'POST',
2626
headers: {
2727
'Accept': 'application/json',
@@ -31,20 +31,19 @@ function Callback() {
3131
code,
3232
client_id: import.meta.env.VITE_NCU_PORTAL_CLIENT_ID,
3333
client_secret: import.meta.env.VITE_NCU_PORTAL_CLIENT_SECRET,
34-
redirect_uri: 'http://localhost:5173/callback',
34+
redirect_uri: 'https://ncuappteam.github.io/callback',
3535
grant_type: 'authorization_code'
3636
})
3737
});
3838

3939
const tokenData = await tokenResponse.json();
40-
4140
if (!tokenData.access_token) {
4241
console.error('取得 access_token 失敗', tokenData);
4342
return;
4443
}
4544

4645
// 取得使用者資訊
47-
const userResponse = await fetch('http://localhost:3000/oauth2/userinfo', {
46+
const userResponse = await fetch('https://ncuapp.davidday.tw/oauth2/userinfo', {
4847
method: 'GET',
4948
headers: {
5049
'Authorization': `Bearer ${tokenData.access_token}`,
@@ -72,4 +71,4 @@ function Callback() {
7271
);
7372
}
7473

75-
export default Callback;
74+
export default Callback;

src/routes/login.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function LoginPage() {
1919
const { redirect: redirectUrl } = Route.useSearch()
2020

2121
const CLIENT_ID = import.meta.env.VITE_NCU_PORTAL_CLIENT_ID;
22-
const REDIRECT_URI = 'http://localhost:5173/callback';
22+
const REDIRECT_URI = 'https://ncuappteam.github.io/callback';
2323

2424
const handleLogin = () => {
2525
const oauthURL = `https://portal.ncu.edu.tw/oauth2/authorization?response_type=code&client_id=${CLIENT_ID}&redirect_uri=${REDIRECT_URI}&scope=chinese-name student-id email`;

0 commit comments

Comments
 (0)