diff --git a/src/lib/middleware/demo-authentication.ts b/src/lib/middleware/demo-authentication.ts index 7f98efd06c..e35d4128e1 100644 --- a/src/lib/middleware/demo-authentication.ts +++ b/src/lib/middleware/demo-authentication.ts @@ -11,22 +11,16 @@ function demoAuthentication( { userService }: Pick, { authentication }: Pick, ): void { - app.post(`${basePath}/api/admin/login`, async (req, res) => { + app.post(`${basePath}/auth/demo/login`, async (req, res) => { const { email } = req.body; try { const user = await userService.loginUserWithoutPassword( email, true, ); - const session = req.session || {}; - // @ts-ignore - session.user = user; - // @ts-ignore - req.session = session; - res.status(200) - // @ts-ignore - .json(req.session.user) - .end(); + //@ts-ignore + req.session.user = user; + return res.status(200).json(user); } catch (e) { res.status(400) .json({ error: `Could not sign in with ${email}` }) @@ -67,7 +61,7 @@ function demoAuthentication( .status(401) .json( new AuthenticationRequired({ - path: `${basePath}/api/admin/login`, + path: `${basePath}/auth/demo/login`, type: 'demo', message: 'You have to identify yourself in order to use Unleash.', diff --git a/src/test/e2e/api/admin/bootstrap.test.ts b/src/test/e2e/api/admin/bootstrap.test.ts index 1db7dbbff6..2f70a44643 100644 --- a/src/test/e2e/api/admin/bootstrap.test.ts +++ b/src/test/e2e/api/admin/bootstrap.test.ts @@ -20,7 +20,7 @@ afterAll(async () => { test('Should get ui-bootstrap data', async () => { // login await app.request - .post('/api/admin/login') + .post('/auth/demo/login') .send({ email, }) diff --git a/src/test/e2e/api/admin/feature.auth.e2e.test.ts b/src/test/e2e/api/admin/feature.auth.e2e.test.ts index de4a6b8a0d..894bc143d0 100644 --- a/src/test/e2e/api/admin/feature.auth.e2e.test.ts +++ b/src/test/e2e/api/admin/feature.auth.e2e.test.ts @@ -18,7 +18,7 @@ test('creates new feature toggle with createdBy', async () => { const { request, destroy } = await setupAppWithAuth(db.stores); // Login - await request.post('/api/admin/login').send({ + await request.post('/auth/demo/login').send({ email: 'user@mail.com', }); diff --git a/src/test/e2e/api/admin/feature.custom-auth.e2e.test.ts b/src/test/e2e/api/admin/feature.custom-auth.e2e.test.ts index 6b5803cdcb..f51767033f 100644 --- a/src/test/e2e/api/admin/feature.custom-auth.e2e.test.ts +++ b/src/test/e2e/api/admin/feature.custom-auth.e2e.test.ts @@ -26,7 +26,7 @@ test('should require authenticated user', async () => { .status('401') .json( new AuthenticationRequired({ - path: '/api/admin/login', + path: '/auth/demo/login', type: 'custom', message: 'You have to identify yourself.', }), diff --git a/src/test/e2e/api/admin/user.test.ts b/src/test/e2e/api/admin/user.test.ts index c93952c6a4..4afd602a44 100644 --- a/src/test/e2e/api/admin/user.test.ts +++ b/src/test/e2e/api/admin/user.test.ts @@ -20,7 +20,7 @@ afterAll(async () => { test('Should get my user data', async () => { // login await app.request - .post('/api/admin/login') + .post('/auth/demo/login') .send({ email, }) diff --git a/src/test/e2e/api/auth/reset-password-controller.e2e.test.ts b/src/test/e2e/api/auth/reset-password-controller.e2e.test.ts index e244c06d80..6c09ef8b03 100644 --- a/src/test/e2e/api/auth/reset-password-controller.e2e.test.ts +++ b/src/test/e2e/api/auth/reset-password-controller.e2e.test.ts @@ -172,7 +172,7 @@ test('Calling validate endpoint with already existing session should destroy ses expect.assertions(0); const { request, destroy } = await setupAppWithAuth(stores); await request - .post('/api/admin/login') + .post('/auth/demo/login') .send({ email: 'user@mail.com', }) @@ -206,7 +206,7 @@ test('Calling reset endpoint with already existing session should logout/destroy token = res.body.token; }); await request - .post('/api/admin/login') + .post('/auth/demo/login') .send({ email: 'user@mail.com', }) diff --git a/website/docs/deploy/google-auth-hook-v3.md b/website/docs/deploy/google-auth-hook-v3.md index 2b8c729b31..fbcf3291dc 100644 --- a/website/docs/deploy/google-auth-hook-v3.md +++ b/website/docs/deploy/google-auth-hook-v3.md @@ -112,13 +112,13 @@ function googleAdminAuth(app) { } ``` -Implement a preRouter hook for `/api/admin/login`. It's necessary for login with Google. +Implement a preRouter hook for `/auth/google/login`. It's necessary for login with Google. ```js function googleAdminAuth(app) { // ... app.get( - '/api/admin/login', + '/auth/google/login', passport.authenticate('google', { scope: ['email'] }), ); // ... @@ -158,7 +158,7 @@ function googleAdminAuth(app) { .status('401') .json( new unleash.AuthenticationRequired({ - path: '/api/admin/login', + path: '/auth/google/login', type: 'custom', message: `You have to identify yourself in order to use Unleash. Click the button and follow the instructions.`, }), @@ -211,7 +211,7 @@ function googleAdminAuth(app) { passport.deserializeUser((user, done) => done(null, user)); app.get( - '/api/admin/login', + '/auth/google/login', passport.authenticate('google', { scope: ['email'] }), ); app.get( @@ -232,7 +232,7 @@ function googleAdminAuth(app) { .status('401') .json( new unleash.AuthenticationRequired({ - path: '/api/admin/login', + path: '/auth/google/login', type: 'custom', message: `You have to identify yourself in order to use Unleash. Click the button and follow the instructions.`, }), diff --git a/website/docs/deploy/google-auth-hook.md b/website/docs/deploy/google-auth-hook.md index b11c5c73d0..f07b9be791 100644 --- a/website/docs/deploy/google-auth-hook.md +++ b/website/docs/deploy/google-auth-hook.md @@ -121,13 +121,13 @@ function googleAdminAuth(app, config, services) { } ``` -Implement a preRouter hook for `/api/admin/login`. It's necessary for login with Google. +Implement a preRouter hook for `/auth/google/login`. It's necessary for login with Google. ```js function googleAdminAuth(app, config, services) { // ... app.get( - '/api/admin/login', + '/auth/google/login', passport.authenticate('google', { scope: ['email'] }), ); // ... @@ -167,7 +167,7 @@ function googleAdminAuth(app, config, services) { .status('401') .json( new unleash.AuthenticationRequired({ - path: '/api/admin/login', + path: '/auth/google/login', type: 'custom', message: `You have to identify yourself in order to use Unleash. Click the button and follow the instructions.`, }), @@ -221,7 +221,7 @@ function googleAdminAuth(app, config, services) { passport.deserializeUser((user, done) => done(null, user)); app.get( - '/api/admin/login', + '/auth/google/login', passport.authenticate('google', { scope: ['email'] }), ); app.get( @@ -242,7 +242,7 @@ function googleAdminAuth(app, config, services) { .status('401') .json( new unleash.AuthenticationRequired({ - path: '/api/admin/login', + path: '/auth/google/login', type: 'custom', message: `You have to identify yourself in order to use Unleash. Click the button and follow the instructions.`, }),