전체 글
-
NextAuth와 Next.js: 미들웨어에서 세션 처리하는 다양한 방법Javascript 2024. 8. 4. 12:07
다음은 Next.js와 NextAuth를 사용하여 미들웨어에서 세션을 확인하는 방법에 대한 보다 구체적인 대안과 이에 대한 실제 코드입니다. 이 글에서는 여러 접근 방안을 제시하고, 각 방법에 대한 간단한 코드 예제를 포함하였습니다. 1. 미들웨어에서 세션을 직접 가져오기먼저, 일반적인 방법으로 세션을 직접 가져오는 코드입니다. 하지만 이 방법은 성능상 이슈가 있을 수 있습니다.// middleware.tsimport type { NextRequest } from "next/server";import { getSession } from "next-auth/react";export async function middleware(req: NextRequest) { const session = await g..
-
한방에 자바스크립트 배열 마스터하기(뽀개기)!Javascript 2024. 8. 3. 11:53
한방에 자바스크립트 배열 마스터하기(뽀개기)! 😎배열 만들기 101배열로 루프 돌리기 🎠배열 조작하기 🛠️요소 하나만 쏙! 뽑아내기요소 여러 개 뽑아내기요소 찾기 🔍요소 값으로 꽉꽉 채우기배열 붙이기 🔗배열 정렬하기 🧹오름차순 (작은 순서대로)내림차순 (큰 순서대로)유연하게 가공하기 🎨중첩 배열 펴기배열을 하나의 값으로 뭉치기!중복 제거하기 🚫마무리 🎉배열 만들기 101배열로 루프 돌리기 🎠배열 조작하기 🛠️요소 하나만 쏙! 뽑아내기요소 여러 개 뽑아내기요소 찾기 🔍요소 값으로 꽉꽉 채우기배열 붙이기 🔗배열 정렬하기 🧹오름차순 (작은 순서대로)내림차순 (큰 순서대로)유연하게 가공하기 🎨중첩 배열 펴기배열을 하나의 값으로 뭉치기!중복 제거하기 🚫마무리 🎉한 여름입니다! 🏖️..
-
Go 1.22의 새로운 기능: cmp.OrGo 2024. 7. 29. 21:12
안녕하세요?Go 1.22가 출시된 지 꽤 많은 시간이 지났는데요. 이제 제가 1.22 버전을 정리하는 시리즈의 마지막을 장식할 때가 왔습니다. 이전에 작성한 reflect.TypeFor와 slices.Concat 함수에 대한 글을 먼저 읽으시는게 좋을 듯 합니다. 오늘 소개할 마지막 함수는 바로 cmp.Or입니다. 실제로 이 함수의 개발자는 Go Time 팟캐스트에서 이 함수를 "1.22의 숨겨진 보석"이라고 소개한 바 있습니다. 간단한 기능이지만 다양한 활용 가능성을 가지고 있으며, 그 탄생 배경에는 놀랍도록 긴 이야기가 숨겨져 있습니다. cmp.Or: 제네릭 기반 조건부 값 선택의 새로운 접근 방식 cmp.Or 함수는 가변 개수의 인자를 받아, 첫 번째 non-zero 값을 반환하는 제네릭 함수입니다..
-
Go 1.22의 새로운 기능: slices.ConcatGo 2024. 7. 29. 21:07
지난 블로그에서는 Go 1.22에 추가된 reflect.TypeFor 함수에 대해 소개해드렸습니다. 이번에는 slices.Concat 함수에 대해 심층적으로 분석해 보겠습니다. slices.Concat: 제네릭 슬라이스 연결의 새로운 패러다임 slices.Concat 함수는 가변 개수의 슬라이스를 입력으로 받아 하나의 새로운 슬라이스로 연결하여 반환하는 제네릭 함수입니다. 이 함수의 시그니처는 다음과 같습니다.// Concat returns a new slice concatenating the passed in slices.func Concat[S ~[]E, E any](slices ...S) S slices.Concat 함수는 제네릭 슬라이스 라이브러리에 필수적인 기능이며, 실제로 저는 2021년 5월..
-
Go 1.22의 새로운 기능: reflect.TypeForGo 2024. 7. 29. 21:02
안녕하세요! Go 1.22가 발표되면서, reflect.TypeFor 함수가 드디어 세상에 공개되었습니다. 오늘은 이 함수의 배경과 기능, 그리고 그 의미에 대해 좀 더 깊이 있게 살펴보도록 하겠습니다. reflect.TypeFor: 제네릭 기반 타입 리플렉션의 새로운 지평 Go 1.18 이후 제네릭이 도입되면서 Go 언어는 타입 안전성과 코드 재사용성 측면에서 큰 진전을 이루었습니다. 이러한 발전의 연장선상에서, reflect.TypeFor 함수는 제네릭을 활용하여 런타임에 타입 정보를 획득하는 새로운 패러다임을 제시합니다. 기존의 reflect.TypeOf 함수는 인터페이스를 통해 전달된 값의 concrete 타입을 반환했습니다. 하지만 인터페이스 자체의 타입 정보는 런타임에 유실되는 문제가 있었죠...
-
Go 1.23의 숨겨진 보석: reflect.Value.Seq와 reflect.Value.Seq2Go 2024. 7. 29. 20:51
Go 프로그래밍 언어는 간결하고 효율적인 코딩을 지향하지만, 이터레이터와 관련된 부분에서는 다소 불편함이 있었습니다. 새로운 Go 1.23 버전에서는 이러한 문제를 해결하기 위해 reflect.Value.Seq와 reflect.Value.Seq2라는 기능이 추가되었습니다. 이 기능들은 다양한 타입을 이터레이터로 변환하여 훨씬 더 쉽게 반복 작업을 수행할 수 있게 해줍니다. 이 글에서는 이 새로운 기능들이 어떤 문제를 해결하고 어떻게 사용되는지에 대해 자세히 살펴보겠습니다. 기존 채널 기반 이터레이터의 문제점Go에서 이터레이터 패턴을 구현할 때 주로 채널을 사용했습니다. 하지만 이 방법에는 몇 가지 문제점이 있었습니다:제네릭이 없어서 타입별로 유틸리티를 작성해야 함: Go 1.18부터 제네릭이 도입되어 이..
-
OAuth 배우기 전에 배우는 웹 인증의 세계 - Basic, Digest, 세션, 토큰 인증 비교Javascript 2024. 7. 17. 21:23
안녕하세요! 오늘은 웹 애플리케이션 개발에 있어 가장 중요한 인증·인가의 기초와 OAuth를 배우기전에 웹 인증의 종류에 대해 비교해서 알아보겠습니다.인증·인가의 기초인증과 인가의 차이인증이란 "사용자가 누구인지"를 확인하는 프로세스이며, 영어로 Authentication이라고 표기합니다.반면에, 인가란 "사용자가 특정 권한을 가지고 있는지"를 확인하는 프로세스이며, 영어로 Authorization이라고 표기합니다. 예를 들어,은행 계좌를 개설할 때는 운전면허증 등을 제출해서 본인임을 확인하는데, 이는 운전면허증을 사용해 계좌를 개설하는 사람이 "누구인지"를 확인하는 것이므로 인증(Authentication)에 해당합니다.반면에 기차에 탑승할 때는 개찰구에 표를 통과시키죠. 이는 표를 사용해 기차에 탑승..
-
TypeScript에서 Array<T>와 T[]의 차이점 이해하기Javascript 2024. 7. 17. 20:51
TypeScript 배열 탐험: Array vs T[] - 당신에게 맞는 선택은? TypeScript는 JavaScript에 강력한 타입 시스템을 더해 코드의 안정성과 예측 가능성을 높여줍니다. 특히, JavaScript의 유연한 배열 다루기를 타입 안정성을 보장하며 수행할 수 있도록 두 가지 방식, Array와 T[]를 제공합니다. 겉보기에는 비슷해 보이는 이 두 방식은 미묘한 차이를 지니고 있으며, 상황에 따라 적절한 선택이 달라질 수 있습니다. 이 글에서는 Array와 T[]의 차이점을 심층 분석하고, 실제로 어떻게 활용되는지 다양한 예제와 함께 살펴보며, 여러분의 프로젝트에 적합한 선택을 할 수 있도록 가이드를 제공합니다. 1. 기본 이해: Array와 T[] - 같은 듯 다른 두 친구Array:..