Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

renders local login form if and only if you're using it #34

Merged
merged 1 commit into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,13 @@ function protectRoutes(site) {
/**
* middleware to show login page
* @param {object} site
* @param {array} currentProviders
* @param {array} providers
* @returns {function}
*/
function onLogin(site, currentProviders) {
function onLogin(site, providers) {
return function (req, res) {
const template = compileLoginPage(),
currentProviders = getProviders(providers, site),
authUrl = getAuthUrl(site),
flash = req.flash();

Expand All @@ -102,7 +103,8 @@ function onLogin(site, currentProviders) {
currentProviders: currentProviders,
user: req.user,
logoutLink: `${authUrl}/logout`,
localAuthPath: `${authUrl}/local`
localAuthPath: `${authUrl}/local`,
useLocalAuth: providers.includes('local')
}));
}
};
Expand Down Expand Up @@ -185,7 +187,7 @@ function init({ router, providers, store, site, storage, bus }) {
// add authorization routes
// note: these (and the provider routes) are added here,
// rather than as route controllers in lib/routes/
router.get('/_auth/login', onLogin(site, currentProviders));
router.get('/_auth/login', onLogin(site, providers));
router.get('/_auth/logout', onLogout(site));
strategyService.addAuthRoutes(providers, router, site); // allow mocking this in tests

Expand Down
3 changes: 2 additions & 1 deletion views/login.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,14 @@
</a>
{{/each}}
</div>
<p class="separator">or</p>
{{/if}}
{{#if useLocalAuth}}
<form class="login-form" action="{{localAuthPath}}" method="post">
<input id="username" name="username" type="text" placeholder="Username" />
<input id="password" name="password" type="password" placeholder="Password" />
<button type="submit">Login</button>
</form>
{{/if}}
{{/if}}
</div>
</div>
Expand Down