Generate AUTH files for basic authentication in surge.sh projects
surge-auth-generator helps generate AUTH files for setting up basic authentication on surge.sh projects.
It makes supporting case insensitive users a breeze.
See surge help for more info on authentication using AUTH files.
$ npm install --save-dev surge-auth-generator
const authGenerator = require('surge-auth-generator');
authGenerator.generate(credentials, directory);
or
const { generate } = require('surge-auth-generator');
generate(credentials, directory);
Create AUTH file in project root for john:doe.
authGenerator.generate({
username: 'john',
password: 'doe'
});
Create AUTH file with case insensitive username in project root
(so authentication will work for 'John', 'john', 'JOHN', ...).
authGenerator.generate({
username: 'john',
password: 'doe',
caseInsensitive: 'true'
});
Create AUTH file in dist folder for multiple users.
authGenerator.generate(
[{
username: 'john',
password: 'doe'
}, {
username: 'jane',
password: 'doe'
}, {
username: 'foo',
password: 'bar'
}], "dist");
The package works with a custom object type for authentication credentials.
Each property is optional and can be left out.
The special property caseInsensitive
can be used to indicate that a username is not case sensitive.
/**
* @interface Credential
*/
interface Credential {
/** authentication username */
username?: string;
/** authentication password */
password?: string;
/** whether the username should be case insensitive */
caseInsensitive?: boolean;
}
AUTH files can be created using the generate function.
The method takes in a credential object or an array of credentials and an optional output path.
All parameters are optional.
The output path defaults to the current project's root directory.
const generate: (credentials?: Credential | Credential[], directory?: string | undefined) => Promise<string>