Skip to content

Commit

Permalink
Add getUserProp util
Browse files Browse the repository at this point in the history
  • Loading branch information
António Santos committed Mar 25, 2020
1 parent 1e053e3 commit b736b6f
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion utils/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export async function redirectAuthenticated(ctx, to = '/') {
ctx.res.end()
} else Router.push('/')
}
} catch (err) { }
} catch (err) {
return {}
}
}

export async function redirectPublic(ctx, to = '/') {
Expand All @@ -29,4 +31,21 @@ export async function redirectPublic(ctx, to = '/') {
ctx.res.end()
} else Router.push('/')
}
}

// returns user prop
export async function getUserProp(ctx) {
try {
const {data: { currentUser }} = await ctx.apolloClient.query({
query: CURRENT_USER_QUERY,
});
return {
user: currentUser,
}
} catch (err) {
console.log(err)
return {
user: null,
}
}
}

1 comment on commit b736b6f

@vercel
Copy link

@vercel vercel bot commented on b736b6f Mar 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.