1
0
Fork 0
mirror of synced 2024-06-30 20:10:54 +12:00

self endpoint, simple auth

This commit is contained in:
Martin McKeaveney 2021-04-12 11:20:01 +01:00
parent e2ce7098c5
commit c4a9d8c9f0
5 changed files with 17 additions and 10 deletions

View file

@ -13,6 +13,8 @@
import { auth } from "stores/backend"
let modal
console.log($auth.user)
</script>
{#if $auth.user}

View file

@ -1,11 +1,16 @@
import { writable, get } from "svelte/store"
import api from "../../builderStore/api"
async function checkAuth() {
const response = await api.get("/api/self")
const user = await response.json()
if (json) return json
}
export function createAuthStore() {
const { subscribe, set } = writable({})
const user = localStorage.getItem("auth:user")
if (user) set({ user: JSON.parse(user) })
checkAuth().then(user => set({ user }))
return {
subscribe,

View file

@ -51,11 +51,11 @@ module.exports = (permType, permLevel = null) => async (ctx, next) => {
// this may need to change in the future, right now only admins
// can have access to builder features, this is hard coded into
// our rules
// if (isAdmin && isAuthed) {
// return next()
// } else if (permType === PermissionTypes.BUILDER) {
// return ctx.throw(403, "Not Authorized")
// }
if (isAuthed) {
return next()
} else if (permType === PermissionTypes.BUILDER) {
return ctx.throw(403, "Not Authorized")
}
if (
hasResource(ctx) &&

View file

@ -10,8 +10,8 @@ exports.authenticate = async (ctx, next) => {
expires.setDate(expires.getDate() + 1)
if (!user) {
ctx.body = { success: false, user }
return
ctx.body = { success: false }
return next()
}
ctx.cookies.set(Cookies.Auth, user.token, {

View file

@ -1,6 +1,6 @@
const Router = require("@koa/router")
const controller = require("../controllers/app")
const authenticated = require("../../middleware/authenticated")
const { authenticated } = require("@budibase/auth")
const router = Router()