self endpoint, simple auth
This commit is contained in:
parent
6499213f90
commit
0548fdc863
|
@ -13,6 +13,8 @@
|
||||||
import { auth } from "stores/backend"
|
import { auth } from "stores/backend"
|
||||||
|
|
||||||
let modal
|
let modal
|
||||||
|
|
||||||
|
console.log($auth.user)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if $auth.user}
|
{#if $auth.user}
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
import { writable, get } from "svelte/store"
|
import { writable, get } from "svelte/store"
|
||||||
import api from "../../builderStore/api"
|
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() {
|
export function createAuthStore() {
|
||||||
const { subscribe, set } = writable({})
|
const { subscribe, set } = writable({})
|
||||||
|
|
||||||
const user = localStorage.getItem("auth:user")
|
checkAuth().then(user => set({ user }))
|
||||||
if (user) set({ user: JSON.parse(user) })
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
subscribe,
|
subscribe,
|
||||||
|
|
|
@ -51,11 +51,11 @@ module.exports = (permType, permLevel = null) => async (ctx, next) => {
|
||||||
// this may need to change in the future, right now only admins
|
// this may need to change in the future, right now only admins
|
||||||
// can have access to builder features, this is hard coded into
|
// can have access to builder features, this is hard coded into
|
||||||
// our rules
|
// our rules
|
||||||
// if (isAdmin && isAuthed) {
|
if (isAuthed) {
|
||||||
// return next()
|
return next()
|
||||||
// } else if (permType === PermissionTypes.BUILDER) {
|
} else if (permType === PermissionTypes.BUILDER) {
|
||||||
// return ctx.throw(403, "Not Authorized")
|
return ctx.throw(403, "Not Authorized")
|
||||||
// }
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
hasResource(ctx) &&
|
hasResource(ctx) &&
|
||||||
|
|
|
@ -10,8 +10,8 @@ exports.authenticate = async (ctx, next) => {
|
||||||
expires.setDate(expires.getDate() + 1)
|
expires.setDate(expires.getDate() + 1)
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
ctx.body = { success: false, user }
|
ctx.body = { success: false }
|
||||||
return
|
return next()
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.cookies.set(Cookies.Auth, user.token, {
|
ctx.cookies.set(Cookies.Auth, user.token, {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const Router = require("@koa/router")
|
const Router = require("@koa/router")
|
||||||
const controller = require("../controllers/app")
|
const controller = require("../controllers/app")
|
||||||
const authenticated = require("../../middleware/authenticated")
|
const { authenticated } = require("@budibase/auth")
|
||||||
|
|
||||||
const router = Router()
|
const router = Router()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue