Skip to content

Instantly share code, notes, and snippets.

@devinivy
Created October 6, 2015 15:34
Show Gist options
  • Save devinivy/8dca9e01bf256c085dfb to your computer and use it in GitHub Desktop.
Save devinivy/8dca9e01bf256c085dfb to your computer and use it in GitHub Desktop.
A mock auth scheme for testing
// Mock scheme for testing
server.auth.scheme('mock', function(server, options) {
return {
authenticate: function(request, reply) {
reply({credentials: options});
}
};
});
// To register a strategy that logs you in with this canned record
server.strategy('testing-strategy', 'mock', { user: { id: 1, username: 'baby-matt' } });
@SwethaSelva
Copy link

SwethaSelva commented Apr 5, 2023

const mockSchema = function () {
const authenticate = async (_request: Request, h: ResponseToolkit): Promise<Hapi.Auth<Hapi.UserCredentials>> =>{
h.authenticated({ credentials: {}});
}
return { authenticate };
};
server.auth.scheme('mock', mockSchema);
server.auth.strategy(<strategy_name>, 'mock');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment