jr-auth-cli 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { Command } from 'commander';
|
|
4
|
+
import inquirer from 'inquirer';
|
|
5
|
+
import fs from 'fs-extra';
|
|
6
|
+
import chalk from 'chalk';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
import { fileURLToPath } from 'url';
|
|
9
|
+
import { exec } from 'child_process';
|
|
10
|
+
import util from 'util';
|
|
11
|
+
import ora from 'ora';
|
|
12
|
+
|
|
13
|
+
const execPromise = util.promisify(exec);
|
|
14
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
15
|
+
const __dirname = path.dirname(__filename);
|
|
16
|
+
|
|
17
|
+
// Inquirer fix
|
|
18
|
+
const prompt = inquirer.prompt ?? inquirer.default?.prompt ?? inquirer.default;
|
|
19
|
+
|
|
20
|
+
const DEPENDENCIES = {
|
|
21
|
+
firebase: "firebase",
|
|
22
|
+
betterauth: "better-auth",
|
|
23
|
+
jwt: "jsonwebtoken bcryptjs cookie",
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
function getPackageManager() {
|
|
27
|
+
const userDir = process.cwd();
|
|
28
|
+
if (fs.existsSync(path.join(userDir, 'yarn.lock'))) return 'yarn add';
|
|
29
|
+
if (fs.existsSync(path.join(userDir, 'pnpm-lock.yaml'))) return 'pnpm add';
|
|
30
|
+
if (fs.existsSync(path.join(userDir, 'bun.lockb'))) return 'bun add';
|
|
31
|
+
return 'npm install';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const program = new Command();
|
|
35
|
+
|
|
36
|
+
program
|
|
37
|
+
.name('my-auth')
|
|
38
|
+
.description('Custom Auth CLI')
|
|
39
|
+
.version('1.0.0');
|
|
40
|
+
|
|
41
|
+
program
|
|
42
|
+
.command('add')
|
|
43
|
+
.description('Add an authentication provider')
|
|
44
|
+
.action(async () => {
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
const answers = await prompt([
|
|
48
|
+
{
|
|
49
|
+
type: 'list',
|
|
50
|
+
name: 'provider',
|
|
51
|
+
message: 'Which auth setup do you need?',
|
|
52
|
+
choices: ['Firebase', 'Better Auth', 'JWT'],
|
|
53
|
+
},
|
|
54
|
+
]);
|
|
55
|
+
|
|
56
|
+
const providerName = answers.provider.toLowerCase().replace(/\s/g, '');
|
|
57
|
+
const spinner = ora('Initializing setup...').start();
|
|
58
|
+
|
|
59
|
+
// সোর্স টেমপ্লেট পাথ
|
|
60
|
+
const templatePath = path.join(__dirname, 'templates', providerName);
|
|
61
|
+
|
|
62
|
+
if (!fs.existsSync(templatePath)) {
|
|
63
|
+
spinner.fail(chalk.red(`Template for ${providerName} not found!`));
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
spinner.text = 'Configuring paths...';
|
|
68
|
+
|
|
69
|
+
// 🔥 Better Auth এর জন্য স্পেশাল লজিক
|
|
70
|
+
if (providerName === 'betterauth') {
|
|
71
|
+
|
|
72
|
+
// ১. কনফিগারেশন ফাইল (auth.ts) যাবে lib ফোল্ডারে
|
|
73
|
+
const libPath = path.join(process.cwd(), 'lib');
|
|
74
|
+
await fs.ensureDir(libPath);
|
|
75
|
+
await fs.copy(
|
|
76
|
+
path.join(templatePath, 'auth.ts'),
|
|
77
|
+
path.join(libPath, 'auth.ts')
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
// ২. API Route ফাইল যাবে app/api/auth/[...all] ফোল্ডারে
|
|
81
|
+
const apiPath = path.join(process.cwd(), 'app', 'api', 'auth', '[...all]');
|
|
82
|
+
await fs.ensureDir(apiPath); // ফোল্ডার না থাকলে বানিয়ে নেবে
|
|
83
|
+
|
|
84
|
+
await fs.copy(
|
|
85
|
+
path.join(templatePath, 'route.ts'),
|
|
86
|
+
path.join(apiPath, 'route.ts')
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
spinner.succeed(chalk.green(`Better Auth setup created at: \n 📄 lib/auth.ts \n ⚡ app/api/auth/[...all]/route.ts`));
|
|
90
|
+
|
|
91
|
+
} else {
|
|
92
|
+
// 🔥 বাকিদের (Firebase/JWT) জন্য সাধারণ লজিক
|
|
93
|
+
const targetPath = path.join(process.cwd(), 'lib', 'auth', providerName);
|
|
94
|
+
await fs.copy(templatePath, targetPath);
|
|
95
|
+
spinner.succeed(chalk.green(`Files copied to /lib/auth/${providerName}`));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// ডিপেন্ডেন্সি ইনস্টল করা
|
|
99
|
+
const packagesToInstall = DEPENDENCIES[providerName];
|
|
100
|
+
if (packagesToInstall) {
|
|
101
|
+
const installCmd = getPackageManager();
|
|
102
|
+
const installSpinner = ora(`${chalk.yellow('Installing:')} ${packagesToInstall}...`).start();
|
|
103
|
+
await execPromise(`${installCmd} ${packagesToInstall}`);
|
|
104
|
+
installSpinner.succeed(chalk.green('Dependencies installed!'));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
console.log('');
|
|
108
|
+
console.log(chalk.bold.cyan('🎉 Setup Complete!'));
|
|
109
|
+
|
|
110
|
+
} catch (err) {
|
|
111
|
+
console.error(chalk.red('\n❌ Error:'), err);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
program.parse(process.argv);
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "jr-auth-cli",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "An awesome CLI to setup authentication instantly for your JavaScript/TypeScript projects using NextAuth.js, Firebase Auth, or custom JWT-based solutions.",
|
|
5
|
+
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"jr-auth": "./index.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
12
|
+
},
|
|
13
|
+
"keywords": ["auth", "cli", "nextjs", "better-auth", "firebase"],
|
|
14
|
+
"author": "MD. JUWEL RANA",
|
|
15
|
+
"license": "ISC",
|
|
16
|
+
"type": "module",
|
|
17
|
+
"files": [
|
|
18
|
+
"index.js",
|
|
19
|
+
"templates"
|
|
20
|
+
],
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"chalk": "^5.6.2",
|
|
23
|
+
"commander": "^14.0.2",
|
|
24
|
+
"fs-extra": "^11.3.3",
|
|
25
|
+
"inquirer": "^13.1.0",
|
|
26
|
+
"ora": "^9.0.0"
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/bcryptjs": "^2.4.6",
|
|
31
|
+
"@types/jsonwebtoken": "^9.0.10",
|
|
32
|
+
"bcryptjs": "^3.0.3",
|
|
33
|
+
"better-auth": "^1.4.9",
|
|
34
|
+
"firebase": "^12.7.0",
|
|
35
|
+
"jsonwebtoken": "^9.0.3",
|
|
36
|
+
"next-auth": "^4.24.13"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { betterAuth } from "better-auth";
|
|
2
|
+
|
|
3
|
+
export const auth = betterAuth({
|
|
4
|
+
// ডিফল্ট হিসেবে ইমেইল পাসওয়ার্ড দেওয়া হলো
|
|
5
|
+
emailAndPassword: {
|
|
6
|
+
enabled: true,
|
|
7
|
+
},
|
|
8
|
+
// সোশ্যাল প্রভাইডার লাগলে এখানে আনকমেন্ট করো
|
|
9
|
+
// socialProviders: {
|
|
10
|
+
// google: {
|
|
11
|
+
// clientId: process.env.GOOGLE_CLIENT_ID as string,
|
|
12
|
+
// clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
|
|
13
|
+
// },
|
|
14
|
+
// },
|
|
15
|
+
|
|
16
|
+
// মনে রেখো: Better Auth এর জন্য ডাটাবেস এডাপ্টার লাগে (Prisma/Drizzle)
|
|
17
|
+
// database: prismaAdapter(prisma, { provider: "postgresql" }),
|
|
18
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { initializeApp } from "firebase/app";
|
|
2
|
+
import { getAuth } from "firebase/auth";
|
|
3
|
+
|
|
4
|
+
const firebaseConfig = {
|
|
5
|
+
apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY,
|
|
6
|
+
authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN,
|
|
7
|
+
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
|
|
8
|
+
storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET,
|
|
9
|
+
messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
|
|
10
|
+
appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const app = initializeApp(firebaseConfig);
|
|
14
|
+
export const auth = getAuth(app);
|
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import jwt from 'jsonwebtoken';
|
|
2
|
+
|
|
3
|
+
const SECRET = process.env.JWT_SECRET || 'secret';
|
|
4
|
+
|
|
5
|
+
export const signToken = (payload: object) => {
|
|
6
|
+
return jwt.sign(payload, SECRET, { expiresIn: '1d' });
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const verifyToken = (token: string) => {
|
|
10
|
+
try {
|
|
11
|
+
return jwt.verify(token, SECRET);
|
|
12
|
+
} catch (error) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
};
|