diff --git a/packages/builder/src/components/login/ForgotForm.svelte b/packages/builder/src/components/login/ForgotForm.svelte
index df76f72c2d..afadf9f4cf 100644
--- a/packages/builder/src/components/login/ForgotForm.svelte
+++ b/packages/builder/src/components/login/ForgotForm.svelte
@@ -1,10 +1,24 @@
@@ -15,13 +29,13 @@
Forgotten your password?
- No problem! Just enter your account's email address and we'll send
- you a link to reset it.
-
+
+ No problem! Just enter your account's email address and we'll send
+ you a link to reset it.
+
+
- Reset your password
+ Reset your password
diff --git a/packages/builder/src/components/login/LoginForm.svelte b/packages/builder/src/components/login/LoginForm.svelte
index 66441b2a72..df78923965 100644
--- a/packages/builder/src/components/login/LoginForm.svelte
+++ b/packages/builder/src/components/login/LoginForm.svelte
@@ -52,9 +52,9 @@
Sign in to Budibase
- $goto("./forgot")}
- >Forgot password?
+ $goto("./forgot")}>
+ Forgot password?
+
diff --git a/packages/builder/src/components/login/ResetForm.svelte b/packages/builder/src/components/login/ResetForm.svelte
index c78a70fba0..4ae19b1ab1 100644
--- a/packages/builder/src/components/login/ResetForm.svelte
+++ b/packages/builder/src/components/login/ResetForm.svelte
@@ -1,12 +1,23 @@
@@ -17,12 +28,12 @@
Reset your password
- Please enter the new password you'd like to use.
-
+
+ Please enter the new password you'd like to use.
+
+
-
Reset your password
+
Reset your password
diff --git a/packages/builder/src/stores/backend/auth.js b/packages/builder/src/stores/backend/auth.js
index c86836ae0f..40420657ec 100644
--- a/packages/builder/src/stores/backend/auth.js
+++ b/packages/builder/src/stores/backend/auth.js
@@ -33,6 +33,25 @@ export function createAuthStore() {
await response.json()
store.update(state => ({ ...state, user: null }))
},
+ forgotPassword: async email => {
+ const response = await api.post(`/api/admin/auth/reset`, {
+ email,
+ })
+ if (response.status !== 200) {
+ throw "Unable to send email with reset link"
+ }
+ await response.json()
+ },
+ resetPassword: async (password, code) => {
+ const response = await api.post(`/api/admin/auth/reset/update`, {
+ password,
+ resetCode: code,
+ })
+ if (response.status !== 200) {
+ throw "Unable to reset password"
+ }
+ await response.json()
+ },
createUser: async user => {
const response = await api.post(`/api/admin/users`, user)
if (response.status !== 200) {
diff --git a/packages/worker/src/api/controllers/auth.js b/packages/worker/src/api/controllers/auth.js
deleted file mode 100644
index 153f7f8523..0000000000
--- a/packages/worker/src/api/controllers/auth.js
+++ /dev/null
@@ -1,93 +0,0 @@
-const authPkg = require("@budibase/auth")
-const { google } = require("@budibase/auth/src/middleware")
-const { Configs } = require("../../constants")
-const CouchDB = require("../../db")
-const { clearCookie } = authPkg.utils
-const { Cookies } = authPkg.constants
-const { passport } = authPkg.auth
-
-const GLOBAL_DB = authPkg.StaticDatabases.GLOBAL.name
-
-exports.authenticate = async (ctx, next) => {
- return passport.authenticate("local", async (err, user) => {
- if (err) {
- return ctx.throw(403, "Unauthorized")
- }
-
- const expires = new Date()
- expires.setDate(expires.getDate() + 1)
-
- if (!user) {
- return ctx.throw(403, "Unauthorized")
- }
-
- ctx.cookies.set(Cookies.Auth, user.token, {
- expires,
- path: "/",
- httpOnly: false,
- overwrite: true,
- })
-
- delete user.token
-
- ctx.body = { user }
- })(ctx, next)
-}
-
-exports.logout = async ctx => {
- clearCookie(ctx, Cookies.Auth)
- ctx.body = { message: "User logged out" }
-}
-
-/**
- * The initial call that google authentication makes to take you to the google login screen.
- * On a successful login, you will be redirected to the googleAuth callback route.
- */
-exports.googlePreAuth = async (ctx, next) => {
- const db = new CouchDB(GLOBAL_DB)
- const config = await authPkg.db.getScopedFullConfig(db, {
- type: Configs.GOOGLE,
- group: ctx.query.group,
- })
- const strategy = await google.strategyFactory(config)
-
- return passport.authenticate(strategy, {
- scope: ["profile", "email"],
- })(ctx, next)
-}
-
-exports.googleAuth = async (ctx, next) => {
- const db = new CouchDB(GLOBAL_DB)
-
- const config = await authPkg.db.getScopedFullConfig(db, {
- type: Configs.GOOGLE,
- group: ctx.query.group,
- })
- const strategy = await google.strategyFactory(config)
-
- return passport.authenticate(
- strategy,
- { successRedirect: "/", failureRedirect: "/error" },
- async (err, user) => {
- if (err) {
- return ctx.throw(403, "Unauthorized")
- }
-
- const expires = new Date()
- expires.setDate(expires.getDate() + 1)
-
- if (!user) {
- return ctx.throw(403, "Unauthorized")
- }
-
- ctx.cookies.set(Cookies.Auth, user.token, {
- expires,
- path: "/",
- httpOnly: false,
- overwrite: true,
- })
-
- ctx.redirect("/")
- }
- )(ctx, next)
-}