inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

[개정3판] Node.js 교과서 - 기본부터 프로젝트 실습까지

프로젝트 구조 갖추기

저는왜 렌더링 화면이 다를까요 ?

302

작성자 없음

작성한 질문수 0

0

저는 이 화면으로만 보이고 domain 적는 구간이없는데.. 왜그럴까요 계속 로그인 상태 알람만 발생합니다.

 

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>API 서버 로그인</title>
    <style>
      .input-group label { width: 200px; display: inline-block; }
    </style>
  </head>
  <body>
    {% if user and user.id %}
      <span class="user-name">안녕하세요! {{user.nick}}님</span>
      <a href="/auth/logout">
        <button>로그아웃</button>
      </a>
      <fieldset>
        <legend>도메인 등록</legend>
        <form action="/domain" method="post">
          <div>
            <label for="type-free">무료</label>
            <input type="radio" id="type-free" name="type" value="free">
            <label for="type-premium">프리미엄</label>
            <input type="radio" id="type-premium" name="type" value="premium">
          </div>
          <div>
            <label for="host">도메인</label>
            <input type="text" id="host" name="host" placeholder="ex) zerocho.com">
          </div>
          <button>저장</button>
        </form>
      </fieldset>
      <table>
        <tr>
          <th>도메인 주소</th>
          <th>타입</th>
          <th>클라이언트 비밀키</th>
        </tr>
        {% for domain in domains %}
          <tr>
            <td>{{domain.host}}</td>
            <td>{{domain.type}}</td>
            <td>{{domain.clientSecret}}</td>
          </tr>
        {% endfor %}
      </table>
    {% else %}
      <form action="/auth/login" id="login-form" method="post">
        <h2>NodeBird 계정으로 로그인하세요.</h2>
        <div class="input-group">
          <label for="email">이메일</label>
          <input id="email" type="email" name="email" required autofocus>
        </div>
        <div class="input-group">
          <label for="password">비밀번호</label>
          <input id="password" type="password" name="password" required>
        </div>
        <div>회원가입은 localhost:8001에서 하세요.</div>
        <button id="login" type="submit">로그인</button>
      </form>
      <script>
        window.onload = () => {
          if (new URL(location.href).searchParams.get('error')) {
            alert(new URL(location.href).searchParams.get('error'));
          }
        };
      </script>
    {% endif %}
  </body>
</html>
const { User, Domain } = require("../models");
const { v4: uuidv4 } = require("uuid");

exports.renderLogin = async (req, res, next) => {
    try {
        const user = await User.findOne({
            where: { id: res.user?.id || null },
            include: { model: Domain }
        })
        res.render("login", {
            user,
            domains: user?.Domains
        })
    } catch (err) {
        console.error(err)
        next(err);
    }
}

exports.createDomain = async (req, res, next) => {
    try {
        await Domain.create({
            UserId: req.user.id,
            host: req.body.host,
            type: req.body.type,
            client: uuidv4()
        })
        res.redirect("/");
    } catch (err) {
        console.error(err);
        next(err);
    }
}

- app.js에 passport의 initialize(), session() 함수 선언되어있습니다.

 

- cookie도 있습니다.

- db에 user도 있습니다.

node.js mysql mongodb express typescript socket.io jwt

답변 1

0

정채진

index controller에서 User를 찾는 중 request가 아닌 response에서 찾는 코드 실수였습니다

깃헙 질문

0

79

2

강의 1-1 수업노트의 로드맵 링크가 작동하지 않습니다.

0

75

1

aws - lightsail 이용 관련

0

57

1

4강 http 서버 만들때 ESM방식으로 해도 될까요?

0

79

2

모듈 사용 시 단점이 있나요?

0

79

1

node.js 버전 및 typescript 적용 문의

0

92

2

12.7. 방장기능(강퇴) 질문드립니다.

0

78

2

12.7 socket.js코드 그대로 뱃겨서 했는데, socket.request.session.color가안나오네요

0

68

1

12.7 코드 그대로 뱃겨서 햇는데 스샷같이 오류가뜹니다.

0

73

2

12.7.1스스로 해보기 질문되나요

0

89

3

시퀄라이즈 실습하기 질문드립니다.

0

188

9

<7-5. 시퀄라이즈 사용하기>수업 질문 드립니다.

0

94

2

크롬에서 user id를 인풋에 입력하고 등록하면 404 에러처리 페이지가 뜹니다.

0

110

2

구매 결제관련 질문입니다 !

0

121

1

다수의 supertest 가 실행될 때 force:true로 인한 DB 초기화 문제

0

131

2

node 설치 방법이 전혀다르게 바뀐것 같습니다.

0

148

2

12강 깃허브에 있는 12.7 chat.html 복붙했는데 css오류

0

120

2

무료/프리미엄 동시 소유 시 질문

0

115

1

비주얼 스튜디오 코드로 계속 진행해도 괜찮을까요?

0

134

2

10강 cors에러 localhost:4000으로 접속했을때 에러

1

156

2

webstorm 해결할 수 없는 변수 문제

0

152

2

혹시 몽고DB 쓸거면 MySQL 강의 스킵해도 되나요?

0

147

2

LightSail 실행 중 오류 질문드립니다!

0

199

2

RedisStore 사용법 질문

0

131

2