FrontEnd/Next.js
-
cloudinary API를 통해 이미지 업로드 해보기 (feat. Next.js)FrontEnd/Next.js 2024. 9. 6. 11:26
이미지를 업로드 하기 위해 cloudinary 라는 CDN 을 사용해당 api에서는 위젯과 같은 컴포넌트를 제공하지만 ui가 딱히 예쁘다는 생각이 들진 않아서 따로 사용하지 않고 upload api를 통해서 이미지 파일을 올리기로 함. ( 문서 링크 )end point는 아래와 같음https://api.cloudinary.com/v1_1/:cloud_name/:action이것을 통해 직접 입력한 값은 const endPoint = `https://api.cloudinary.com/v1_1/${process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME}/image/upload`;https://www.postman.com/cloudinaryteam/programmable-media/..
-
Credetials callback function handle error (next-auth v5)FrontEnd/Next.js 2024. 6. 17. 12:48
https://github.com/nextauthjs/next-auth/pull/9871 feat: customizable `authorize()` error by balazsorban44 · Pull Request #9871 · nextauthjs/next-authThis introduces a way to throw custom errors in the authorize() callback of the Credentials provider. Any generic or sensitive server error will continue to return error=Configuration (full error i...github.com기존 callback에서는 throw new Error로 처리했지만 C..
-
form에서 server action 다루기FrontEnd/Next.js 2024. 6. 15. 01:12
https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutationsform action에서 server action을 하기 위해서는 비동기 함수를 넘겨주면서 use server를 입력해주면 됨export default function Page() { async function createInvoice(formData: FormData) { 'use server'; const rawFormData = { customerId: formData.get('customerId'), amount: formData.get('amount'), ..
-
Form에서 두개 이상의 버튼을 다루기 (feat. server action )FrontEnd/Next.js 2024. 6. 14. 20:03
Form 안에 두개 이상의 버튼이 있을 경우 어떤 버튼을 클릭했는지에 따라 행하는 액션이 다를 수 있다.이 때 button의 name와 value 속성을 이용하면 form의 action에서 버튼의 주체를 파악할 수 있다.form action에서 넘겨주는 파라미터는 FormData로써 폼 안에 버튼을 클릭하면 해당하는 버튼의 name과 value 정보가 포함되어져 있다.(이 때 form 안에 input 필드가 있다면 input들의 name과 value들도 출력 됨.)import { signIn } from '@/auth';function SignIn() { const handleAction = async (data: FormData) => { 'use server'; cons..
-
인가 서버에서 token 받아오기 (OAuth) feat. NextJsFrontEnd/Next.js 2024. 6. 10. 20:18
next-auth를 사용하면 provider를 통해 oauth 구현이 쉽겠지만 oauth에 대해 알고 있는 로직을 직접 구현해보고 싶어졌음https://developers.kakao.com/docs/latest/ko/kakaologin/common Kakao Developers카카오 API를 활용하여 다양한 어플리케이션을 개발해보세요. 카카오 로그인, 메시지 보내기, 친구 API, 인공지능 API 등을 제공합니다.developers.kakao.com카카오 로그인 문서에 따르면 oauth의 로직은 아래 이미지와 같다메인 페이지(Home)에 있는 카카오 로그인 버튼을 누르면 아래의 함수가 실행된다.const HomePage = () => { const handleKakaoLogin = () => { ..
-
next.js 에 kakao map 띄우기 (feat. react-kakao-maps-sdk)FrontEnd/Next.js 2024. 2. 6. 15:31
카카오 개발자 센터에 들어가보면 api key (자바스크립트 키) 를 발급 후 아래 코드를 삽입하라고 한다. "API를 로딩하는 스크립트 태그는 HTML파일안의 head, body 등 어떠한 위치에 넣어도 상관없습니다. 하지만, 반드시 실행 코드보다 먼저 선언되어야 합니다." 리액트 같은 경우에는 intex.html에 작성하면 되고 next.js 같은 경우 layout 같은 곳에 Script 태그를 불러와 삽입하면 된다. 하지만 이 같은 번거로운 작업을 JaeSeoKim 님이 배포하신 라이브러리를 사용하면 비교적 간단하게 처리 할 수 있다. next.js 같은 경우 example에 따르면 .env 에 아래와 같이 작성해두면 script 문을 따로 작성하는 대신 useKakaoLoader를 통해 api 키..
-
[next.js] react-quill 에디터 값을 출력하기 (feat. dangerouslySetInnerHTML )FrontEnd/Next.js 2024. 1. 31. 22:20
import 'react-quill/dist/quill.snow.css'; import { EditorProvideProps } from '../new/new-types'; // 중간 생략 ReactQuill에 입력한 데이터 value는 html 요소를 string 형태로 받아와짐 (++참고) next.js에서 ReactQuill 컴포넌트를 사용할려면 dynamic으로 import 해야함. (window로 정의 되어 있는데 next는 서버 측에서 작동하니 아래처럼 dynamic으로 받아오면서 ssr:false 넣어주기. + useMemo를 하지 않으면 렌더링 될 때마다 변경되어보림) const ReactQuill = useMemo( () => dynamic(() => import('react-quill'..
-
Link , Router 비교FrontEnd/Next.js 2023. 11. 16. 16:03
페이지 이동시 태그를 사용하는 것은 SPA 페이지인 Next.js 에서 효율적이지 못함. a 태그로 이동 시 새로고침을 하기 때문에 그 과정에서 빈 화면이 보일 수도 있고 통신을 새롭게 하다 보니 성능 및 사용자 경험 측면에서 떨어질 수 밖에 없다. 새로고침 없이 페이지 이동을 위한 (SPA에 위배되지 않기 위해) 라우팅 방식에는 와 Router 가 있음 1. Link Link 태그에는 href 속성을 추가하여 가고자 하는 주소(페이지)를 넣는다 새로고침 없이 페이지 전환이 됨. Client-side navigation 방식으로 , JS로 페이지 전환이 이뤄짐 is a React component that extends the HTML element to provide prefetching and cli..