Skip to content

Commit

Permalink
fix: fix accessing user credentials after signing in
Browse files Browse the repository at this point in the history
  • Loading branch information
dziraf committed Aug 3, 2022
1 parent 248007f commit 4a6fdd9
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const register = async (server: Hapi.Server, options: ExtendedAdminJSOptions) =>
options: opts,
handler: async (request, h) => {
try {
const loggedInUser = request.auth && request.auth.credentials;
const loggedInUser = request.auth?.credentials?.[0];

This comment has been minimized.

Copy link
@x-ray-s

x-ray-s Aug 11, 2022

if using array index, please modify the doc, because the authenticate function needs to return the same type, in this way I can get the correct value of currentAdmin. or instead of object extend.

// ...hapi options
auth: {
  authenticate: (email, password) => {
     return [{
       id: '1',
      role: 'admin'
     }]
  }
}

// in actions opitons
edit: ({currentAdmin}) => {
  return currentAdmin.role === 'admin'
}

This comment has been minimized.

Copy link
@dziraf

dziraf Aug 11, 2022

Author Contributor

@x-ray-s are you sure? In my test app I returned an object in authenticate function but it was stored at first index of request.auth.credentials array 🤔

This comment has been minimized.

Copy link
@dziraf

dziraf Aug 11, 2022

Author Contributor

before updating hapi libraries request.auth.credentials was an object though.

This comment has been minimized.

Copy link
@LorenzoLeonardini

LorenzoLeonardini Nov 29, 2022

before updating hapi libraries request.auth.credentials was an object though.

What version of the hapi libraries are you using? Everything I'm using is newer than the versions in the peerDependencies list and request.auth.credentials is not an array :\

const controller = new route.Controller({ admin }, loggedInUser);
const ret = await controller[route.action](request, h);
const response = h.response(ret);
Expand Down

0 comments on commit 4a6fdd9

Please sign in to comment.