1
0
Fork 0
mirror of synced 2024-07-04 22:11:23 +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" import { auth } from "stores/backend"
let modal let modal
console.log($auth.user)
</script> </script>
{#if $auth.user} {#if $auth.user}

View file

@ -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,

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 // 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) &&

View file

@ -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, {

View file

@ -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()