Skip to content

Commit

Permalink
Update auth.js
Browse files Browse the repository at this point in the history
DEVOPS: Refactor method getUser
  • Loading branch information
Pelirrojo authored Aug 18, 2020
1 parent ef60201 commit c0e0b69
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/utils/auth.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// https://donaldmanuel.com/gatsby-authentication-cognito
// https://www.gatsbyjs.org/tutorial/authentication-tutorial/

const isBrowser = typeof window !== `undefined`

export const setUser = user => (window.localStorage.gatsbyUser = JSON.stringify(user))

const getUser = () => {
if (window.localStorage.gatsbyUser) {
let user = JSON.parse(window.localStorage.gatsbyUser)
return user ? user : {}
}
return {}
}
const getUser = () =>
isBrowser() && window.localStorage.getItem("gatsbyUser")
? JSON.parse(window.localStorage.getItem("gatsbyUser"))
: {}

export const isLoggedIn = () => {
if (!isBrowser) return false
Expand Down

0 comments on commit c0e0b69

Please sign in to comment.