Skip to content

Commit

Permalink
app-admin-ui: Support auth strategies that have loginPath property, c…
Browse files Browse the repository at this point in the history
  • Loading branch information
zenflow committed Apr 5, 2020
1 parent 10aa5ee commit f06410a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/empty-emus-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystonejs/app-admin-ui': minor
---

Support auth strategies that have `loginPath` property
8 changes: 6 additions & 2 deletions packages/app-admin-ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class AdminUIApp {
throw new Error("Admin path cannot be the root path. Try; '/admin'");
}

if (authStrategy && authStrategy.authType !== 'password') {
throw new Error('Keystone 5 Admin currently only supports the `PasswordAuthStrategy`');
if (authStrategy && authStrategy.authType !== 'password' && !authStrategy.loginPath) {
throw new Error('Keystone 5 Admin does not support the given auth strategy');
}

this.adminPath = adminPath;
Expand Down Expand Up @@ -139,6 +139,10 @@ class AdminUIApp {
if (req.user) {
return res.redirect(req.query.redirect || '/');
}
if (this.authStrategy && this.authStrategy.loginPath) {
const query = req.url.split('?')[1] || '';
return res.redirect(`${this.authStrategy.loginPath}?${query}`);
}
next();
});

Expand Down

0 comments on commit f06410a

Please sign in to comment.