업비트 API 자동거래 테스트4

session 로그인 구현

Posted by ETHAN KIM on March 16, 2022 · 1 min read
Node.js

필요기능

  • 암호화된 key파일 및 비밀번호/아이디를 통한 local전략 실행
  • session 확인할 시 복호화 작업

./passport/localStrategy.js

로그인 체크 (단순 객체 )
const passport = require('passport');
const LocalStrategy = require('passport-local').Strategy;
const user_box = require('../user');

module.exports = () => {
    passport.use(new LocalStrategy({
        usernameField: 'id',
        passwordField: 'auth_code',
    }, async (id, auth_code, done) => {
        try { 
            const id_chk = user_box.hasOwnProperty(id);
            if(id_chk){
                if(auth_code == user_box[id][1]) {
                    done(null, id);
                }else{
                    done(null, false, { message: '비밀번호가 일치하지 않습니다.' });
                }
            }else{
                done(null, false, { message: '가입되지 않은 회원입니다.' });
            }
        } catch (error){
            console.error(error);
            done(error);
        }
    }));
};


로그인 화면