Skip to content

Commit ce3266a

Browse files
committed
chore: allow reset-pass
1 parent 9fad9f2 commit ce3266a

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

bin/reset-pass.sh

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
# ONLY AVAILABLE IN DEV MODE
4+
# This command will fail if server is not running in dev mode.
5+
if [[ ! -d .nitro ]]; then
6+
ln -s .nuxt .nitro
7+
fi
8+
9+
if [ ! $# -eq 2 ]
10+
then
11+
echo "No arguments supplied"
12+
echo "Usage: bin/reset-pass.sh <email> <password>"
13+
else
14+
echo "Resetting password for $1"
15+
npx nitro task run chore:reset-pass --payload "{ \"email\": \"$1\", \"password\": \"$2\" }"
16+
fi

docs/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,17 @@ This command starts both the `db` and `app` services using the `dev` profile, ru
105105

106106
You can also pull the latest Docker image from [here](https://hub.docker.com/r/profilecity/vidur/tags).
107107

108+
### Resetting Admin Password
109+
110+
It you forget admin password while development, you can reset it by following these steps.
111+
112+
1. Start vidur project. Make sure it's running on port `3000`.
113+
2. Now, open second terminal and run following command:
114+
115+
```sh
116+
yarn chore:reset-pass -- <email> <new password>
117+
```
118+
108119
## Contributing
109120

110121
We welcome contributions from the community! Check out our [contribution guide](./CONTRIBUTING.md) to get involved and help us make Vidur even better.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"generate": "nuxt generate",
1111
"preview": "nuxt preview",
1212
"postinstall": "nuxt prepare",
13+
"chore:reset-pass": "bash ./bin/reset-pass.sh",
1314
"migration:generate": "drizzle-kit generate",
1415
"migration:apply": "drizzle-kit migrate",
1516
"drizzle:update": "drizzle-kit up",

server/tasks/chore/reset-pass.ts

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { eq } from 'drizzle-orm';
2+
import { adminsTable } from '~~/server/db/schema';
3+
4+
export default defineTask({
5+
meta: {
6+
name: 'chore:reset-pass',
7+
description: "Helps reset a user's password",
8+
},
9+
async run({ payload }) {
10+
try {
11+
const db = await useDatabase();
12+
13+
const email = payload.email as string;
14+
const newPassword = payload.password as string;
15+
16+
await db
17+
.update(adminsTable)
18+
.set({
19+
password: await hashPassword(newPassword),
20+
})
21+
.where(eq(adminsTable.email, email));
22+
23+
console.log(`chore:reset-pass success. ${new Date().toISOString()}`);
24+
return { result: true };
25+
} catch (error) {
26+
console.error(`chore:reset-pass failed. ${new Date().toISOString()}`, error);
27+
return { result: false };
28+
}
29+
},
30+
});

0 commit comments

Comments
 (0)