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

Commit

Permalink
refactor(src/common/api/AuthSvc): move functions that manipulates wit…
Browse files Browse the repository at this point in the history
…h cookies and localStorage to own LocalStorageCookies service
  • Loading branch information
Metnew committed Aug 10, 2017
1 parent a509ed7 commit 1d89e3c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
23 changes: 0 additions & 23 deletions src/common/api/AuthSvc/index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,4 @@
import {post} from 'api/utils'
import * as store from 'store2'
import Cookies from 'js-cookie'

export const JWT_TOKEN = 'JWT_TOKEN'

export function getLocalToken () {
const token = store.get(JWT_TOKEN) || Cookies.get(JWT_TOKEN)
return token
}

export function resetLocalToken () {
store.remove(JWT_TOKEN)
Cookies.remove(JWT_TOKEN)
}

export function setLocalToken (token) {
store.set(JWT_TOKEN, token)
Cookies.set(JWT_TOKEN, token, {expires: 365})
}

export function isLoggedIn () {
return !!getLocalToken()
}

export async function loginAPI (data) {
return post('/auth', data)
Expand Down
23 changes: 23 additions & 0 deletions src/common/api/LocalStorageCookiesSvc/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as store from 'store2'
import Cookies from 'js-cookie'

export const JWT_TOKEN = 'JWT_TOKEN'

export function getLocalToken () {
const token = store.get(JWT_TOKEN) || Cookies.get(JWT_TOKEN)
return token
}

export function resetLocalToken () {
store.remove(JWT_TOKEN)
Cookies.remove(JWT_TOKEN)
}

export function setLocalToken (token) {
store.set(JWT_TOKEN, token)
Cookies.set(JWT_TOKEN, token, {expires: 365})
}

export function isLoggedIn () {
return !!getLocalToken()
}

0 comments on commit 1d89e3c

Please sign in to comment.