Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
✅ Deploy Preview for taskify-deploy ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Contributor
KingNono1030
left a comment
There was a problem hiding this comment.
로그인 기능에 대해 큰 고민 없이 접근 했어서, 로그인 기능 리팩토링에 대한 욕심이 있었는데
효정님께서 좋은 예시가 되어 주셔서, 저도 자극 받고 리팩토링 힘내보겠습니다..!
Comment on lines
+1
to
+25
| 'use server' | ||
| import { cookies } from 'next/headers' | ||
| import { redirect } from 'next/navigation' | ||
|
|
||
| import api from '@/lib/axiosServer' | ||
|
|
||
| import { LoginFormValue } from './components/LoginForm' | ||
|
|
||
| export default async function loginAction(data: LoginFormValue) { | ||
| // 백엔드 요청 | ||
| try { | ||
| const response = await api.post('/auth/login', data, {}) | ||
| const { accessToken, user } = response.data | ||
|
|
||
| // 가져온 json token 쿠키 설정 하기 | ||
| cookies().set('Authorization', accessToken, { | ||
| secure: true, | ||
| // httpOnly: true, | ||
| expires: new Date(Date.now() + 24 * 60 * 60 * 1000 * 3), | ||
| // path: '/', | ||
| sameSite: 'strict', | ||
| }) | ||
| } catch (error: any) { | ||
| return error.response?.data?.message || error.message | ||
| } |
Contributor
There was a problem hiding this comment.
서버 액션 이렇게 적용하는 거군요...!
감사합니다 큰 공부가 되네요
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
resolved: #206
로그인 수정했습니다.
요 정도 수정한 것 같습니다.
제가 수정한 기존 소스는
기존에 로그인 하면서 대시보드 데이터와 유저 데이터도 같이 세션 스토리지에 저장하고 있었는데,
유저 데이터는 세션 스토리지에 저장하는 걸 getUser하는 부분으로 옮김
(대시보드 데이터는 따로 처리하지 않았는데 잘 나오네요)
기존 useRedirect 주석 처리
꼭 머지하려는 건 아니고 이런 방식으로 구현하는 방법 연구했다고 생각해주심 될 거 같습니다.
참고 : https://www.youtube.com/watch?v=INwOeQ0RagY
제가 어렵게 생각했던 부분이
이 세 가지 정도로 정리할 수 있을 것 같은데,
axios 클라이언트를 분리해야한다는 생각을 못해서 axios 인터셉터가 여기저기 꼬이다보니까
이것들을 어떻게 처리해야할지 고민이 많았습니다.
특히 2번이 이해가 잘 안 가다 보니까 전체적인 그림을 어떻게 그려야할 지 몰라서 많이 헤맸는데, 분리가 답이었네요
httpOnly옵션을 써서 서버사이드에서만 적용할 수 있도록 작성해볼까 했는데, 이미 클라이언트에서 api호출을 다 하고 있어 전체적인 구조 변경이 불가피 하더라구요
그래서 일단 두 가지로 이원화해봤습니다.