Вызов JWT.sign()
с пропущенным обратным вызовом выполнит его асинхронно - это то, что вы делаете, это означает, что вызов вернет undefined
, что вы и возвращаете.
Вы можете либо обещать этот вызов, либо синхронно вызывать JWT.sign
, который затем будет возвращен как обещание блока compare(..).then(...)
.
Чтобы «обещать» этот обратный вызов, ваш оператор возврата должен выглядеть примерно так:
return compare(password, dbPwdHash.password)
.then(
(res) => {
if (res) {
return new Promise((resolve, reject) => {
sign({id: dbPwdHash.id}, this.privateKey, {algorithm: 'ES512'}, (err, token) => {
if (err) {
reject(err);
} else {
console.log(token);
resolve({data: token});
}
});
});
}
;
}
)
.catch(
(err) => {
console.log(err);
},
);
ссылка: https://github.com/auth0/node-jsonwebtoken#jwtsignpayload- secretorprivatekey-опции обратного вызова
Начиная с Java 6, это поддерживается в SystemTray
и TrayIcon
] классы. SystemTray
имеет довольно обширный пример в своих Javadocs:
TrayIcon trayIcon = null;
if (SystemTray.isSupported()) {
// get the SystemTray instance
SystemTray tray = SystemTray.getSystemTray();
// load an image
Image image = Toolkit.getDefaultToolkit().getImage("your_image/path_here.gif");
// create a action listener to listen for default action executed on the tray icon
ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
// execute default action of the application
// ...
}
};
// create a popup menu
PopupMenu popup = new PopupMenu();
// create menu item for the default action
MenuItem defaultItem = new MenuItem(...);
defaultItem.addActionListener(listener);
popup.add(defaultItem);
/// ... add other items
// construct a TrayIcon
trayIcon = new TrayIcon(image, "Tray Demo", popup);
// set the TrayIcon properties
trayIcon.addActionListener(listener);
// ...
// add the tray image
try {
tray.add(trayIcon);
} catch (AWTException e) {
System.err.println(e);
}
// ...
} else {
// disable tray option in your application or
// perform other actions
...
}
// ...
// some time later
// the application state has changed - update the image
if (trayIcon != null) {
trayIcon.setImage(updatedImage);
}
// ...
Вы также можете проверить эту статью или этот технический совет .