Skip to content

Commit

Permalink
delete: session token from session
Browse files Browse the repository at this point in the history
  • Loading branch information
Kosei805 committed Nov 14, 2024
1 parent f21e84d commit 46df57c
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 15 deletions.
4 changes: 2 additions & 2 deletions frontend/app/routes/home._index/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export const action = async ({ request }: ActionFunctionArgs) => {
}

const cookieHeader = [
`__Secure-user_id=${session.get('user')};`,
`__Secure-session_token=${session.get('sessionToken')}`,
`__Secure-user_id=${session.get('user')?.id};`,
`__Secure-session_token=${session.get('user')?.sessionToken}`,
].join('; ');

// prettier-ignore
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/routes/home.books.$bookId.edit/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const action = async ({ request }: ActionFunctionArgs) => {

const cookieHeader = [
`__Secure-user_id=${session.get('user')?.id};`,
`__Secure-session_token=${session.get('sessionToken')}`,
`__Secure-session_token=${session.get('user')?.sessionToken}`,
].join('; ');
const formData = await request.formData();

Expand Down
6 changes: 3 additions & 3 deletions frontend/app/routes/home.books.$bookId/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const loader = async ({ params, request }: LoaderFunctionArgs) => {
headers: {
Cookie: [
`__Secure-user_id=${session.get('user')?.id}`,
`__Secure-session_token=${session.get('sessionToken')}`,
`__Secure-session_token=${session.get('user')?.sessionToken}`,
].join('; '),
},
},
Expand All @@ -71,8 +71,8 @@ export const action = async ({ request }: ActionFunctionArgs) => {
}

const cookieHeader = [
`__Secure-user_id=${session.get('user')};`,
`__Secure-session_token=${session.get('sessionToken')}`,
`__Secure-user_id=${session.get('user')?.id};`,
`__Secure-session_token=${session.get('user')?.sessionToken}`,
].join('; ');
const formData = await request.formData();

Expand Down
4 changes: 2 additions & 2 deletions frontend/app/routes/home.cart/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export const action = async ({ request }: ActionFunctionArgs) => {
}

const cookieHeader = [
`__Secure-user_id=${session.get('user')};`,
`__Secure-session_token=${session.get('sessionToken')}`,
`__Secure-user_id=${session.get('user')?.id};`,
`__Secure-session_token=${session.get('user')?.sessionToken}`,
].join('; ');

// prettier-ignore
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/routes/home.global.books.$isbn/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const action = async ({ request }: ActionFunctionArgs) => {

const cookieHeader = [
`__Secure-user_id=${session.get('user')?.id};`,
`__Secure-session_token=${session.get('sessionToken')}`,
`__Secure-session_token=${session.get('user')?.sessionToken}`,
].join('; ');

const requestBody = await request.json<CreateBookBody>();
Expand Down
6 changes: 2 additions & 4 deletions frontend/app/routes/home/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export const action = async ({ request }: ActionFunctionArgs) => {

if (response.status === 204) {
session.unset('user');
session.unset('sessionToken');
session.flash('success', 'ログアウトに成功しました');

return redirect('/home', {
Expand Down Expand Up @@ -103,10 +102,9 @@ const Home = () => {
useEffect(() => {
if (navigation.state === 'idle') {
if (!!userData) {
// CookieにユーザIDが存在する
// Cookieにユーザ情報が保存されている
if (!user) {
// 状態変数にユーザ情報が保存されていない
// ユーザ情報を取得するAPIを呼び出す
// 状態変数にユーザ情報を保存する
setUser(userData);
}
} else {
Expand Down
1 change: 0 additions & 1 deletion frontend/app/routes/login/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export const action = async ({ request }: ActionFunctionArgs) => {
// ログインに成功した場合
if (response.status === 200) {
session.set('user', response.data);
session.set('sessionToken', response.data.sessionToken!);
session.flash('success', 'ログインに成功しました');

return redirect('/home/mypage', {
Expand Down
1 change: 0 additions & 1 deletion frontend/app/services/session.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { User } from 'client/client.schemas';

interface SessionData {
user: User;
sessionToken: string;
}

interface SessionFlashData {
Expand Down

0 comments on commit 46df57c

Please sign in to comment.