File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed
doc/7/controllers/auth/create-api-key/snippets Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change 1818 */
1919
2020 console . log ( 'API key successfully created' ) ;
21+
22+ // Then use it with your client. Note: You don't need to call login after this because this bypasses the authentication system.
23+ kuzzle . setAPIKey ( apiKey . _source . token )
2124} catch ( e ) {
2225 console . error ( e ) ;
2326}
Original file line number Diff line number Diff line change @@ -620,6 +620,19 @@ export class Kuzzle extends KuzzleEventEmitter {
620620 return this . protocol . connect ( ) ;
621621 }
622622
623+ /**
624+ * Set this client to use a specific API key.
625+ *
626+ * After doing this you don't need to use login as it bypasses the authentication process.
627+ */
628+ public setAPIKey ( apiKey : string ) {
629+ if ( apiKey . match ( / ^ k a p i k e y - / ) === null ) {
630+ throw new Error ( "Invalid API key. Missing the `kapikey-` prefix." ) ;
631+ }
632+
633+ this . jwt = apiKey ;
634+ }
635+
623636 async _reconnect ( ) {
624637 if ( this . _reconnectInProgress ) {
625638 return ;
You can’t perform that action at this time.
0 commit comments