mirror of
https://github.com/Ravinou/borgwarehouse
synced 2024-06-03 14:32:38 +02:00
feat: add users.json to .gitignore #12
This commit is contained in:
parent
cda9818225
commit
d43389f395
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -107,4 +107,5 @@ dist
|
||||||
.env*.local
|
.env*.local
|
||||||
|
|
||||||
# config file for BorgWarehouse
|
# config file for BorgWarehouse
|
||||||
config/repo.json
|
config/repo.json
|
||||||
|
config/users.json
|
|
@ -2,7 +2,7 @@
|
||||||
import NextAuth from 'next-auth';
|
import NextAuth from 'next-auth';
|
||||||
import CredentialsProvider from 'next-auth/providers/credentials';
|
import CredentialsProvider from 'next-auth/providers/credentials';
|
||||||
import { verifyPassword } from '../../../helpers/functions/auth';
|
import { verifyPassword } from '../../../helpers/functions/auth';
|
||||||
import { promises as fs } from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
////Use if need getServerSideProps and therefore unstable_getServerSession
|
////Use if need getServerSideProps and therefore unstable_getServerSession
|
||||||
|
@ -14,7 +14,23 @@ export const authOptions = {
|
||||||
//Read the users file
|
//Read the users file
|
||||||
//Find the absolute path of the json directory
|
//Find the absolute path of the json directory
|
||||||
const jsonDirectory = path.join(process.cwd(), '/config');
|
const jsonDirectory = path.join(process.cwd(), '/config');
|
||||||
let usersList = await fs.readFile(
|
//Check if the users.json file exists and initialize it if not with admin/admin.
|
||||||
|
if (!fs.existsSync(jsonDirectory + '/users.json')) {
|
||||||
|
fs.writeFileSync(
|
||||||
|
jsonDirectory + '/users.json',
|
||||||
|
JSON.stringify([
|
||||||
|
{
|
||||||
|
id: 0,
|
||||||
|
email: 'admin@demo',
|
||||||
|
username: 'admin',
|
||||||
|
password:
|
||||||
|
'$2a$12$20yqRnuaDBH6AE0EvIUcEOzqkuBtn1wDzJdw2Beg8w9S.vEqdso0a',
|
||||||
|
roles: ['admin'],
|
||||||
|
},
|
||||||
|
])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
let usersList = await fs.promises.readFile(
|
||||||
jsonDirectory + '/users.json',
|
jsonDirectory + '/users.json',
|
||||||
'utf8'
|
'utf8'
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue