https://github.com/nextcloud-libraries/nextcloud-password-confirmation
Promise-based password confirmation wrapper for Nextcloud https://npmjs.org/@nextcloud/password-confirmation
https://github.com/nextcloud-libraries/nextcloud-password-confirmation
nextcloud-plugin
Last synced: 11 months ago
JSON representation
Promise-based password confirmation wrapper for Nextcloud https://npmjs.org/@nextcloud/password-confirmation
- Host: GitHub
- URL: https://github.com/nextcloud-libraries/nextcloud-password-confirmation
- Owner: nextcloud-libraries
- License: other
- Created: 2018-09-11T07:41:33.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2025-04-03T20:34:53.000Z (11 months ago)
- Last Synced: 2025-04-04T15:45:09.447Z (11 months ago)
- Topics: nextcloud-plugin
- Language: TypeScript
- Homepage:
- Size: 3.77 MB
- Stars: 5
- Watchers: 2
- Forks: 6
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Authors: AUTHORS.md
Awesome Lists containing this project
README
# @nextcloud/password-confirmation
[](https://api.reuse.software/info/github.com/nextcloud-libraries/nextcloud-password-confirmation)
[](https://www.npmjs.com/package/@nextcloud/password-confirmation)
[](https://github.com/nextcloud-libraries/nextcloud-password-confirmation/actions?query=branch%3Amain)
[](https://github.com/nextcloud-libraries/nextcloud-password-confirmation/blob/main/LICENSE)
Promise-based password confirmation for Nextcloud.
This library exports a function that displays a password confirmation dialog when called and returns a promise. This makes it easier to integrate with other asynchronous operations.
## Versions compatibility
| Nextcloud | @nextcloud/vue | @nextcloud/password-confirmation |
| ----------- | -------------- | -------------------------------- |
| 28+ | 8.x | 5.x |
| 25.x - 27.x | 7.x | 2.x - 4.x |
| < 25.x | - | 1.x |
## Installation
```sh
npm add @nextcloud/password-confirmation
```
## Usage
### Direct usage
```js
import { confirmPassword } from '@nextcloud/password-confirmation'
import '@nextcloud/password-confirmation/style.css' // Required for dialog styles
const foo = async () => {
try {
await confirmPassword()
// Your logic
} catch (error) {
// Your error handling logic
}
}
```
### Usage with axios interceptor
```js
import axios from '@nextcloud/axios'
import { addPasswordConfirmationInterceptors, PwdConfirmationMode } from '@nextcloud/password-confirmation'
import '@nextcloud/password-confirmation/style.css' // Required for dialog styles
addPasswordConfirmationInterceptors(axios)
const foo = async () => {
try {
const response = await axios.request({
confirmPassword: PwdConfirmationMode.Strict,
method,
url,
data: this.getData(),
})
// Your logic
} catch (error) {
// Your error handling logic
}
}
```
## API Reference
```ts
/**
* Check if password confirmation is required according to the last confirmation time.
* Use as a replacement of deprecated `OC.PasswordConfirmation.requiresPasswordConfirmation()`.
* Not needed if `confirmPassword()` can be used, because it checks requirements itself.
*
* @return {boolean} Whether password confirmation is required or was confirmed recently
*/
declare function isPasswordConfirmationRequired(): boolean
/**
* Confirm password if needed.
* Replacement of deprecated `OC.PasswordConfirmation.requirePasswordConfirmation(callback)`
*
* @return {Promise} Promise that resolves when password is confirmed or not needded.
* Rejects if password confirmation was cancelled
* or confirmation is already in process.
*/
declare function confirmPassword(): Promise
/**
* Lax: Confirm password if needed.
* Strict: Confirm in the request.
*/
export enum PwdConfirmationMode {
Lax = 'lax',
Strict = 'strict',
}
```
## Releasing
1) Create release branch
2) Adjust version using `npm version vx.y.z --no-git-tag-version`
3) Update `CHANGELOG.md`
4) Commit and open PR
5) After merge, pull latest main
6) `git tag vx.y.z`
7) `git push origin vx.y.z`
8) `npm ci && npm run build && npm publish`