Skip to content

Commit a7b87ae

Browse files
authored
Merge pull request NCUAppTeam#144 from 1989ONCE/main
feat: integrate the data access from oauth to sign up process page
2 parents 8706d92 + 47eda33 commit a7b87ae

File tree

5 files changed

+257
-312
lines changed

5 files changed

+257
-312
lines changed

src/main.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { RouterProvider, createRouter } from '@tanstack/react-router'
12
import React from 'react'
23
import ReactDOM from 'react-dom/client'
3-
import { RouterProvider, createRouter } from '@tanstack/react-router'
44
import './index.css'
55

66
// Import the generated route tree
@@ -18,6 +18,9 @@ declare module '@tanstack/react-router' {
1818
interface Register {
1919
router: typeof router
2020
}
21+
interface HistoryState {
22+
post?: { userData: string };
23+
}
2124
}
2225

2326
ReactDOM.createRoot(document.getElementById('root')!).render(

src/routeTree.gen.ts

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,18 @@
1111
// Import Routes
1212

1313
import { Route as rootRoute } from './routes/__root'
14-
import { Route as SignupImport } from './routes/signup'
15-
import { Route as SignImport } from './routes/sign'
16-
import { Route as LoginImport } from './routes/login'
14+
import { Route as CalendarIndexImport } from './routes/calendar/index'
1715
import { Route as CallbackImport } from './routes/callback'
18-
import { Route as IndexImport } from './routes/index'
19-
import { Route as SalesIndexImport } from './routes/sales/index'
20-
import { Route as MapIndexImport } from './routes/map/index'
16+
import { Route as EventsEventIdImport } from './routes/events/$eventId'
17+
import { Route as EventsCreateImport } from './routes/events/create'
2118
import { Route as EventsIndexImport } from './routes/events/index'
22-
import { Route as CalendarIndexImport } from './routes/calendar/index'
23-
import { Route as HomeInfoCardImport } from './routes/home/infoCard'
2419
import { Route as EventsSelectImport } from './routes/events/select'
25-
import { Route as EventsCreateImport } from './routes/events/create'
26-
import { Route as EventsEventIdImport } from './routes/events/$eventId'
20+
import { Route as HomeInfoCardImport } from './routes/home/infoCard'
21+
import { Route as IndexImport } from './routes/index'
22+
import { Route as LoginImport } from './routes/login'
23+
import { Route as MapIndexImport } from './routes/map/index'
24+
import { Route as SalesIndexImport } from './routes/sales/index'
25+
import { Route as SignupImport } from './routes/signup'
2726

2827
// Create/Update Routes
2928

@@ -32,11 +31,6 @@ const SignupRoute = SignupImport.update({
3231
getParentRoute: () => rootRoute,
3332
} as any)
3433

35-
const SignRoute = SignImport.update({
36-
path: '/sign',
37-
getParentRoute: () => rootRoute,
38-
} as any)
39-
4034
const LoginRoute = LoginImport.update({
4135
path: '/login',
4236
getParentRoute: () => rootRoute,
@@ -117,13 +111,6 @@ declare module '@tanstack/react-router' {
117111
preLoaderRoute: typeof LoginImport
118112
parentRoute: typeof rootRoute
119113
}
120-
'/sign': {
121-
id: '/sign'
122-
path: '/sign'
123-
fullPath: '/sign'
124-
preLoaderRoute: typeof SignImport
125-
parentRoute: typeof rootRoute
126-
}
127114
'/signup': {
128115
id: '/signup'
129116
path: '/signup'
@@ -196,7 +183,6 @@ export interface FileRoutesByFullPath {
196183
'/': typeof IndexRoute
197184
'/callback': typeof CallbackRoute
198185
'/login': typeof LoginRoute
199-
'/sign': typeof SignRoute
200186
'/signup': typeof SignupRoute
201187
'/events/$eventId': typeof EventsEventIdRoute
202188
'/events/create': typeof EventsCreateRoute
@@ -212,7 +198,6 @@ export interface FileRoutesByTo {
212198
'/': typeof IndexRoute
213199
'/callback': typeof CallbackRoute
214200
'/login': typeof LoginRoute
215-
'/sign': typeof SignRoute
216201
'/signup': typeof SignupRoute
217202
'/events/$eventId': typeof EventsEventIdRoute
218203
'/events/create': typeof EventsCreateRoute
@@ -229,7 +214,6 @@ export interface FileRoutesById {
229214
'/': typeof IndexRoute
230215
'/callback': typeof CallbackRoute
231216
'/login': typeof LoginRoute
232-
'/sign': typeof SignRoute
233217
'/signup': typeof SignupRoute
234218
'/events/$eventId': typeof EventsEventIdRoute
235219
'/events/create': typeof EventsCreateRoute
@@ -247,7 +231,6 @@ export interface FileRouteTypes {
247231
| '/'
248232
| '/callback'
249233
| '/login'
250-
| '/sign'
251234
| '/signup'
252235
| '/events/$eventId'
253236
| '/events/create'
@@ -262,7 +245,6 @@ export interface FileRouteTypes {
262245
| '/'
263246
| '/callback'
264247
| '/login'
265-
| '/sign'
266248
| '/signup'
267249
| '/events/$eventId'
268250
| '/events/create'
@@ -277,7 +259,6 @@ export interface FileRouteTypes {
277259
| '/'
278260
| '/callback'
279261
| '/login'
280-
| '/sign'
281262
| '/signup'
282263
| '/events/$eventId'
283264
| '/events/create'
@@ -294,7 +275,6 @@ export interface RootRouteChildren {
294275
IndexRoute: typeof IndexRoute
295276
CallbackRoute: typeof CallbackRoute
296277
LoginRoute: typeof LoginRoute
297-
SignRoute: typeof SignRoute
298278
SignupRoute: typeof SignupRoute
299279
EventsEventIdRoute: typeof EventsEventIdRoute
300280
EventsCreateRoute: typeof EventsCreateRoute
@@ -310,7 +290,6 @@ const rootRouteChildren: RootRouteChildren = {
310290
IndexRoute: IndexRoute,
311291
CallbackRoute: CallbackRoute,
312292
LoginRoute: LoginRoute,
313-
SignRoute: SignRoute,
314293
SignupRoute: SignupRoute,
315294
EventsEventIdRoute: EventsEventIdRoute,
316295
EventsCreateRoute: EventsCreateRoute,
@@ -337,7 +316,6 @@ export const routeTree = rootRoute
337316
"/",
338317
"/callback",
339318
"/login",
340-
"/sign",
341319
"/signup",
342320
"/events/$eventId",
343321
"/events/create",
@@ -358,9 +336,6 @@ export const routeTree = rootRoute
358336
"/login": {
359337
"filePath": "login.tsx"
360338
},
361-
"/sign": {
362-
"filePath": "sign.tsx"
363-
},
364339
"/signup": {
365340
"filePath": "signup.tsx"
366341
},

src/routes/callback.tsx

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { createFileRoute, useNavigate } from '@tanstack/react-router';
2-
import { useEffect, useState } from 'react';
2+
import { useEffect } from 'react';
33

44
export const Route = createFileRoute('/callback')({
55
component: Callback,
66
})
77

88
function Callback() {
99
const navigate = useNavigate();
10-
const [userInfo, setUserInfo] = useState(null);
1110

1211
useEffect(() => {
1312
async function handleOAuthCallback() {
@@ -43,7 +42,7 @@ function Callback() {
4342
console.error('取得 access_token 失敗', tokenData);
4443
return;
4544
}
46-
45+
4746
// 取得使用者資訊
4847
const userResponse = await fetch('http://localhost:3000/oauth2/userinfo', {
4948
method: 'GET',
@@ -55,9 +54,8 @@ function Callback() {
5554

5655
const userData = await userResponse.json();
5756
console.log('使用者資訊:', userData);
58-
setUserInfo(userData);
59-
60-
navigate({ to: '/signup', search: {userData: JSON.stringify(userData)}});
57+
const stringifyData: string = JSON.stringify(userData);
58+
navigate({ to: '/signup', state: { post: { userData: stringifyData } } }) // 導向註冊頁面,並傳遞使用者資訊
6159
} catch (error) {
6260
console.error('OAuth 登入失敗:', error);
6361
navigate({ to: '/' });
@@ -70,12 +68,6 @@ function Callback() {
7068
return (
7169
<div>
7270
<h2>正在處理登入...</h2>
73-
{userInfo && (
74-
<div>
75-
<h3>使用者資訊:</h3>
76-
<pre>{JSON.stringify(userInfo, null, 2)}</pre>
77-
</div>
78-
)}
7971
</div>
8072
);
8173
}

0 commit comments

Comments
 (0)