Skip to content

Commit

Permalink
docs(example): improve example project to show login errors in homepage
Browse files Browse the repository at this point in the history
Closes #11
  • Loading branch information
adrianbrs committed Sep 22, 2022
1 parent c858b6f commit 1c9ac44
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 4 additions & 2 deletions example/src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ export class AppController {
if (session?.accountId) {
const grant = await provider.Grant.find(session.grantIdFor('test'));
return {
query: ctx.query,
accountId: session.accountId,
scopes: grant.getOIDCScopeEncountered()
scopes: grant?.getOIDCScopeEncountered()
}
}

return {
query: ctx.query,
accountId: null,
scopes: null
}
Expand All @@ -42,7 +44,7 @@ export class AppController {
const { code, error, error_description } = query;

if (error) {
return res.json({ error, error_description })
return res.redirect(`/?error=${error}&error_description=${error_description}`);
}

if (!code) {
Expand Down
13 changes: 13 additions & 0 deletions example/views/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@
</div>
</div>

<%
if (query.error || query.error_description) { %>
<div class="row">
<div class="col">
<div class="alert alert-danger mx-auto" style="max-width: 500px;">
<p class="m-0"><strong>error:</strong> <%= query.error %></p>
<p class="m-0"><strong>error_description:</strong> <%= query.error_description %></p>
</div>
</div>
</div>
<% } %>
%>

<div class="row">
<div class="col">
<div class="card mx-auto" style="width: 300px">
Expand Down

0 comments on commit 1c9ac44

Please sign in to comment.