• 로그인
  • 장바구니에 상품이 없습니다.

home2 게시판 Next.js 게시판 Prisma + Azure MySQL로 인증기능 해봄

Prisma + Azure MySQL로 인증기능 해봄

2 글 보임 - 1 에서 2 까지 (총 2 중에서)
  • 글쓴이
  • #129752

    김지한
    참가자
    강의 따라하면서 개인적으로 꼭 prisma를 한번 해보고싶어서 그걸로 바꿔서 해봤습니다.
    
    
    import NextAuth from "next-auth";
    import GithubProvider from "next-auth/providers/github";
    import { PrismaAdapter } from "@next-auth/prisma-adapter";
    import { prisma } from "@/lib/client";
    import CredentialsProvider from "next-auth/providers/credentials";
    import bcrypt from "bcrypt";
    export const authOptions = {
      adapter: PrismaAdapter(prisma),
      secret: process.env.jwt_secret,
      providers: [
        GithubProvider({
          clientId: process.env.git_client_id,
          clientSecret: process.env.git_client_secret, //       clientSecret: process.env.git_client_secret,
        }),
    
    
    다른 부분은 거의 다 비슷하고 어댑터 부분은 prisma로 쓴다는 차이점 있더군요.
    PrismaAdapter 내부에 인자로 들어가는 prisma는, prisma 클라이언트로 DB 모델이 바뀌면 새로 생성을해줬야 했습니다.
     
    github 인증기능을 저렇게 어댑터 붙여서 쓸때, 
    
    github에서 필요로 하는 이런  테이블들을 미리 schema.prisma 에 복사해 넣으셔야 하고요.
    
    model member {
      id         String       @id @db.VarChar(100)
      password   String       @db.VarChar(100)
      createDate DateTime?    @db.DateTime(0)
      modifyDate DateTime?    @db.DateTime(0)
      email      String?      @db.VarChar(100)
      role       member_role? @default(norm)
      name       String       @unique(map: "member_unique") @db.VarChar(100)
    }
    enum member_role {
      norm
      admin
      mentor
    }
    model board {
      id            String    @id @map("_id") @db.VarChar(100)
      content       String?   @db.Text
      title         String    @db.VarChar(100)
      datetime      DateTime? @db.DateTime(0)
      edit_datetime DateTime? @db.DateTime(0)
      email         String?   @db.VarChar(100)
    }
    model User {
      id            String    @id @default(cuid())
      name          String?
      email         String?   @unique
      emailVerified DateTime?
      image         String?
      accounts      Account[]
      sessions      Session[]
      posts         Post[]
    }
    model Post {
      id            Int      @id @default(autoincrement())
      title         String
      code          String   @db.Text
      language      String
      totalLikes    Int      @default(0)
      totalComments Int      @default(0)
      createdAt     DateTime @default(now())
      updatedAt     DateTime @updatedAt
      userId        String
      user          User     @relation(fields: [userId], references: [id])
    }
    model Account {
      id                 String  @id @default(cuid())
      userId             String
      type               String
      provider           String
      providerAccountId  String
      refresh_token      String?  @db.Text
      access_token       String?  @db.Text
      expires_at         Int?
      token_type         String?
      scope              String?
      id_token           String?  @db.Text
      session_state      String?
      user User @relation(fields: [userId], references: [id], onDelete: Cascade)
      @@unique([provider, providerAccountId])
    }
    model Session {
      id           String   @id @default(cuid())
      sessionToken String   @unique
      userId       String
      expires      DateTime
      user         User     @relation(fields: [userId], references: [id], onDelete: Cascade)
    }
    model VerificationToken {
      identifier String
      token      String   @unique
      expires    DateTime
      @@unique([identifier, token])
    }
    prisma 처음 써봐서 좀 삽질을 했는데, DBeaver같은데서(깃헙모델이 아닌 다른) 데이타베이스 칼럼수정하고
    npx prisma introspect
    
    이렇게 모델로 땡겨오다가는 prisma의 깃허브모델 깨져서 인증 망가지는 경우들이 생기더라고요.
    
    반드시 prisma에서 모델 생성해서
    npx prisma migrate dev --name init
    DB 생성하는 형식으로 가야 안전했습니다.
     
    ScreenShot_20240819160916
    재밌었습니당. ㅎㅎ
    
    
    코딩애플 선생님 덕분에 쉽게 배웠어요.
    • 이 게시글은 김지한에 의해 10 월, 3 주 전에 수정됐습니다.
    • 이 게시글은 김지한에 의해 10 월, 3 주 전에 수정됐습니다.
    #129764

    codingapple
    키 마스터
    지렸구요
    
    
2 글 보임 - 1 에서 2 까지 (총 2 중에서)
  • 답변은 로그인 후 가능합니다.

About

현재 월 700명 신규수강중입니다.

  (09:00~20:00) 빠른 상담은 카톡 플러스친구 코딩애플 (링크)
  admin@codingapple.com
  이용약관
ⓒ Codingapple, 강의 예제, 영상 복제 금지
top

© Codingapple, All rights reserved. 슈퍼로켓 에듀케이션 / 서울특별시 강동구 고덕로 19길 30 / 사업자등록번호 : 212-26-14752 온라인 교육학원업 / 통신판매업신고번호 : 제 2017-서울강동-0002 호 / 개인정보관리자 : 박종흠