Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

Core JS library for Lemoncloud; written by Typescript

Notifications You must be signed in to change notification settings

lemoncloud-io/lemon-front-lib

Repository files navigation

lemon-front-lib build status npm package

Core JS library for Lemoncloud; written by Typescript

Install

$ npm install @lemoncloud/lemon-front-lib
// or
$ yarn add @lemoncloud/lemon-front-lib

Usage

import { AuthService } from '@lemoncloud/lemon-front-lib';

const oAuthEndpoint = 'http://localhost:8086'; // refresh 때 필요
const project = 'LEMON';
const authService = new AuthService({ project, oAuthEndpoint });

Authentication

buildCredentialsByToken()

oauth api를 통해 발급 받은 token으로 AWS Credentials 생성

const ENDPOINT = 'https://..../oauth/kakao/token'; // lemoncloud oauth-api
const body = { code }; // get from kakao, naver, google...

const credentials = authService.requestWithSign('POST', ENDPOINT, '/', {}, body)
    .then(data => authService.buildCredentialsByToken(data));

isAuthenticated()

AWS Credentials 데이터 유무로 로그인 체크

AuthService.isAuthenticated();

getCredentials()

AWS Credentials 리턴. 로그인하지 않았을 경우 null 리턴

AuthService.getCredentials();

request()

axios를 이용한 HTTP 요청. AWS Credentials이 있을 경우, Signature V4 Signing 과정을 거쳐 요청

AuthService.request('GET', 'YOUR_URL', '/');
AuthService.request('GET', 'YOUR_URL', '/', { page: 0 });
AuthService.request('POST', 'YOUR_URL', '/', {}, { mock: 'MOCK_VALUE' });

requestWithCredentials()

내부에서 getCredentials()을 호출 후 request() 진행

AuthService.requestWithCredentials('GET', 'YOUR_URL', '/');
AuthService.requestWithCredentials('GET', 'YOUR_URL', '/', { page: 0 });
AuthService.requestWithCredentials('POST', 'YOUR_URL', '/', {}, { mock: 'MOCK_VALUE' });

logout()

AWS Credentials 데이터 삭제

AuthService.logout();

Example

$ node example/example.js
# open localhost:8888 on browser