npm install base-64

.d.ts 를 지원하므로 typescript로 작성한다면 @types/basic-64를 설치하면 됨.

 

import base64 from 'base-64';

let username = 'user';
let password = 'passwd';

let headers = new Headers();

//headers.append('Content-Type', 'text/json');
headers.append('Authorization', 'Basic' + base64.encode(username + ":" + password));

fetch(url, {method:'GET',
        headers: headers,
        //credentials: 'user:passwd'
       })
.then(response => response.json())
.then(json => console.log(json));
//.done();

function parseJSON(response) {
return response.json()
}

나의 경우 아래와 같이 작성함

        let data = {
            method: 'POST',
            // body: JSON.stringify({

            // })
            headers: {
                Accept: 'application/json',
                'Content-Type': 'application/json',
                'Authorization': 'Basic ' + base64.encode('user:password')
            }
        }

        fetch(`http://url`,data)
        .then((response)=>response.json())
        .then((json)=>{
            console.log(json);
        })

 

 

 

 

 

공격자

1. accessToken 탈취

  - 만료기간이 짧아 시간이 지나면 자연스레 사용 불가

 

2. refreshToken 탈취

 - 이중 로그인 시 가장 마지막에 로그인한 refresh Token만 가능 (새로이 갱신이 되므로)

   이전의 refreshToken은 사용 불가

 

 

단점) 이렇게 하면 서버 쪽에 (굳이 서버쪽 아니고 위에서는 DB) 저장을 해두고 사용해야됨.

       또한 생각보다 저 과정이 자주 일어나서 리소스가 빡쎄다

스크롤 뷰 안에 flatList를 넣으려고 할 때 위와 같은 메세지가 출력된다.

Warning error

 

<FlatList nestedScrollEnabled />

 

React Native 0.41 이상일 경우

<ScrollView
    ref={ref => this.scrollView = ref}
    onContentSizeChange={(contentWidth, contentHeight)=>{        
        this.scrollView.scrollToEnd({animated: true});
    }}>
</ScrollView>

 

flatList에서

 

<FlatList

      ref={'flatList'}

      data={this.state.message}

      renderItem={({ item }) => this._onRefresh(item)}

      keyExtractor={(itemindexnumber=> { return index.toString() }}

     onContentSizeChange={(contentWidthcontentHeight)=>{

           (this.refs.flatList as FlatList).scrollToEnd({animated: true});

           }}

/>

 

 

 

 

한동안 자료구조와 알고리즘 공부에 손을 놔서 6월달부터 향후 1년간 빠짐없이 공부하려고 한다...

이를 위해 mac 노트북에 C++ 작업 환경을 구축할 필요가 있었으며,

VS Code 상에서 C++ 빌드하는 방법을 기록해둔다.

 

 

task.json 생성 후 task를 아래와 같이 변경한다.

"tasks": [
        {
            "label": "build file",
            "type": "shell",
            "command": "g++",
            "args": [
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}",
                "${file}"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": [
                "$gcc"
            ]
        },
        {
            "label": "run file",
            "type": "shell",
            "command": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": []
        },
    ]

 

이후 cmd + shift + B 를 누르고 Build -> run 순으로 진행한다.

 

출처 : https://younghk.github.io/VS-Code-C++-Configuration-For-Mac/

+ Recent posts