Skip to content

Commit

Permalink
feat: use withAuthenticated
Browse files Browse the repository at this point in the history
  • Loading branch information
ooooorobo committed Aug 22, 2024
1 parent 83fd959 commit 94355f7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/app/routes/form.$key.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { CompletePage } from 'src/pages/form/complete/CompletePage';
import { useProfileFirstName } from 'src/entities/profile/lib/useProfileFirstName';
import { Shortcut } from 'src/processes/shortcut/Shortcut';
import styles from 'src/app/styles/form.module.css';
import { saveInfo, validateLink } from 'src/types';
import { saveInfo } from 'src/types';
import { ActionFunctionArgs, json, LoaderFunctionArgs } from '@remix-run/node';
import { useLoaderData } from '@remix-run/react';

Expand All @@ -30,8 +30,8 @@ export const loader = async ({ params }: LoaderFunctionArgs) => {
const { key } = params;
if (!key) throw new Response('', { status: 404 });

const { data } = await validateLink(key);
if (!data.isValid) throw new Response('', { status: 404 });
// const { data } = await validateLink(key);
// if (!data.isValid) throw new Response('', { status: 404 });

return json({ linkKey: key });
};
Expand Down
10 changes: 3 additions & 7 deletions src/app/routes/profile.$key.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { LoaderFunctionArgs } from '@remix-run/node';
import { ProfilePage } from 'src/pages/profile/ProfilePage';
import { getInfo } from 'src/types';
import { getAuthSession } from 'src/app/server/sessions';
import { authenticate } from 'src/app/server/authenticate';
import { withAuthenticated } from 'src/app/server/withAuthenticated';
import { useLoaderData } from '@remix-run/react';
import { MyProfileProvider } from 'src/entities/profile/model/myProfileStore';
import { IdealPartnerProvider } from 'src/entities/ideal_partner/model/idealPartnerStore';
import { useMemo } from 'react';
import { convertDtoToProfile } from 'src/entities/profile/model/convertProfileToDto';
import { convertDtoToIdealPartner } from 'src/entities/ideal_partner/model/convertIdealPartnerToDto';

export const loader = async ({ params, request }: LoaderFunctionArgs) => {
export const loader = withAuthenticated(async ({ params }, accessToken) => {
const { key } = params;

if (!key) {
Expand All @@ -20,16 +18,14 @@ export const loader = async ({ params, request }: LoaderFunctionArgs) => {
});
}

const session = await getAuthSession(request);
const accessToken = await authenticate(request, session);
const { data } = await getInfo(key, {
headers: {
Authorization: `Bearer ${accessToken}`,
},
});

return { profile: data };
};
});

export default function Page() {
const { profile } = useLoaderData<typeof loader>();
Expand Down
2 changes: 1 addition & 1 deletion src/pages/mypage/MyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const MyPage = () => {
return (
<>
<div className={styles.Header}>
<Link to={'/?login=true'}>
<Link to={'/'}>
<Close />
</Link>
<h2>마이페이지</h2>
Expand Down

0 comments on commit 94355f7

Please sign in to comment.