Skip to content

Commit

Permalink
chore: allow reset-pass
Browse files Browse the repository at this point in the history
  • Loading branch information
amandesai01 committed Mar 1, 2025
1 parent 9fad9f2 commit ce3266a
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
16 changes: 16 additions & 0 deletions bin/reset-pass.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

# ONLY AVAILABLE IN DEV MODE
# This command will fail if server is not running in dev mode.
if [[ ! -d .nitro ]]; then
ln -s .nuxt .nitro
fi

if [ ! $# -eq 2 ]
then
echo "No arguments supplied"
echo "Usage: bin/reset-pass.sh <email> <password>"
else
echo "Resetting password for $1"
npx nitro task run chore:reset-pass --payload "{ \"email\": \"$1\", \"password\": \"$2\" }"
fi
11 changes: 11 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ This command starts both the `db` and `app` services using the `dev` profile, ru

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

### Resetting Admin Password

It you forget admin password while development, you can reset it by following these steps.

1. Start vidur project. Make sure it's running on port `3000`.
2. Now, open second terminal and run following command:

```sh
yarn chore:reset-pass -- <email> <new password>
```

## Contributing

We welcome contributions from the community! Check out our [contribution guide](./CONTRIBUTING.md) to get involved and help us make Vidur even better.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"generate": "nuxt generate",
"preview": "nuxt preview",
"postinstall": "nuxt prepare",
"chore:reset-pass": "bash ./bin/reset-pass.sh",
"migration:generate": "drizzle-kit generate",
"migration:apply": "drizzle-kit migrate",
"drizzle:update": "drizzle-kit up",
Expand Down
30 changes: 30 additions & 0 deletions server/tasks/chore/reset-pass.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { eq } from 'drizzle-orm';
import { adminsTable } from '~~/server/db/schema';

export default defineTask({
meta: {
name: 'chore:reset-pass',
description: "Helps reset a user's password",
},
async run({ payload }) {
try {
const db = await useDatabase();

const email = payload.email as string;
const newPassword = payload.password as string;

await db
.update(adminsTable)
.set({
password: await hashPassword(newPassword),
})
.where(eq(adminsTable.email, email));

console.log(`chore:reset-pass success. ${new Date().toISOString()}`);
return { result: true };
} catch (error) {
console.error(`chore:reset-pass failed. ${new Date().toISOString()}`, error);
return { result: false };
}
},
});

0 comments on commit ce3266a

Please sign in to comment.