diff --git a/package.json b/package.json index 925abeb..8c68971 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "packageManager": "pnpm@9.8.0+sha512.8e4c3550fb500e808dbc30bb0ce4dd1eb614e30b1c55245f211591ec2cdf9c611cabd34e1364b42f564bd54b3945ed0f49d61d1bbf2ec9bd74b866fcdc723276", "dependencies": { "@supabase/supabase-js": "^2.45.4", + "dotenv": "^17.2.2", "jsonwebtoken": "^9.0.2", "nodemailer": "^6.9.15", "pg": "^8.13.0" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3c67444..cd92b53 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,6 +11,9 @@ importers: '@supabase/supabase-js': specifier: ^2.45.4 version: 2.45.4 + dotenv: + specifier: ^17.2.2 + version: 17.2.2 jsonwebtoken: specifier: ^9.0.2 version: 9.0.2 @@ -70,6 +73,10 @@ packages: buffer-equal-constant-time@1.0.1: resolution: {integrity: sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==} + dotenv@17.2.2: + resolution: {integrity: sha512-Sf2LSQP+bOlhKWWyhFsn0UsfdK/kCWRv1iuA2gXAwt3dyNabr6QSj00I2V10pidqz69soatm9ZwZvpQMTIOd5Q==} + engines: {node: '>=12'} + ecdsa-sig-formatter@1.0.11: resolution: {integrity: sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==} @@ -297,6 +304,8 @@ snapshots: buffer-equal-constant-time@1.0.1: {} + dotenv@17.2.2: {} + ecdsa-sig-formatter@1.0.11: dependencies: safe-buffer: 5.2.1 diff --git a/src/index.ts b/src/index.ts index 5bc725b..df260b3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,27 +3,15 @@ import { QueryResult, QueryData, QueryError } from '@supabase/supabase-js'; import { createClient, AuthClient } from '@supabase/supabase-js'; // const url = 'http://192.168.31.220:8000' // const url = 'http://supabase.xiongxiao.me' -const url = 'http://supabase.xiongxiao.me' - -// const authClient = new AuthClient({ url: url }); -// // const auth = await authClient.signInWithPassword({ email: 'xiongxiao1012@outlook.com', password:'123456xx' }); -// // const auth = await authClient.signInWithPassword({ email: 'admin@zxj.im', password:'123456xx' }); -// const auth = await authClient.signInAnonymously(); -// console.log('auth', auth); +const url = 'http://supabase.xiongxiao.me'; // Create a single supabase client for interacting with your database -const publicAnonKey = - 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.ewogICJyb2xlIjogImFub24iLAogICJpc3MiOiAic3VwYWJhc2UiLAogICJpYXQiOiAxNzI4NTc2MDAwLAogICJleHAiOiAxODg2MzQyNDAwCn0._O6nSz8km61C76qGnRMa44e4sou1qCRBhy8O0riHQmM'; +const publicAnonKey = process.env.PUBLIC_ANON_KEY!; +const serverKEY = process.env.SERVER_KEY!; const supabase = createClient(url, publicAnonKey); -// const anony = await supabase.auth.signInAnonymously(); -// console.log('anony', anony); -// const u = await supabase.auth.signInWithPassword({ -// email: 'xiongxiao1012@outlook.com', -// password: '123456xx', -// }); -// console.log('u', u); -supabase.auth.signInWithSSO + +supabase.auth.signInWithSSO; const countriesWithCitiesQuery = supabase.from('public_test').select(` id, title diff --git a/src/login-admin.ts b/src/login-admin.ts new file mode 100644 index 0000000..af69964 --- /dev/null +++ b/src/login-admin.ts @@ -0,0 +1,19 @@ +import { supabase, supabaseServer } from './module/supabase'; +const u = await supabaseServer.auth.signInWithPassword({ + email: 'xiongxiao@xiongxiao.me', + password: process.env.PASSWORD!, +}); + +// console.log('u', u); + +// const { data: test, error } = await supabase.from('test').select('*'); + +// console.log('test', test, error); + +const res = await supabase.auth.admin.createUser({ + user_metadata: { full_name: 'Xiongxiao' }, + phone: '+8615202829140', + phone_confirm: true, +}); + +console.log('res', res); diff --git a/src/login-by-server.ts b/src/login-by-server.ts index 64c11ad..8700764 100644 --- a/src/login-by-server.ts +++ b/src/login-by-server.ts @@ -1,15 +1,12 @@ import { supabaseServer, supabase } from './module/supabase'; -// const u = await supabase.auth.signInWithPassword({ -// email: 'admin@zxj.im', -// password: '123456xx', -// }); const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIzZjgyZTNhZS1iN2MyLTQyNDQtODQ5Zi1kNDUzZjMwNGIyZjIiLCJhdWQiOiJhdXRoZW50aWNhdGVkIiwiZXhwIjoxNzI5NDE1NDQwLCJpYXQiOjE3Mjk0MTE4NDAsImVtYWlsIjoiYWRtaW5AenhqLmltIiwicGhvbmUiOiIiLCJhcHBfbWV0YWRhdGEiOnsicHJvdmlkZXIiOiJlbWFpbCIsInByb3ZpZGVycyI6WyJlbWFpbCJdfSwidXNlcl9tZXRhZGF0YSI6e30sInJvbGUiOiJhdXRoZW50aWNhdGVkIiwiYWFsIjoiYWFsMSIsImFtciI6W3sibWV0aG9kIjoicGFzc3dvcmQiLCJ0aW1lc3RhbXAiOjE3Mjk0MTE4NDB9XSwic2Vzc2lvbl9pZCI6IjEwOWEyZjZjLWM4NmEtNGVjZC05MzMxLWFhNDEyMzc1NDM1ZCIsImlzX2Fub255bW91cyI6ZmFsc2V9.voDVDh5Qlockr5nmx6Hhe3pcBnm5Aqq6r-aeSY-QUwA'; const simpleToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIzZjgyZTNhZS1iN2MyLTQyNDQtODQ5Zi1kNDUzZjMwNGIyZjIiLCJhdWQiOiJhdXRoZW50aWNhdGVkIiwicm9sZSI6ImF1dGhlbnRpY2F0ZWQiLCJpYXQiOjE3Mjk0MTIzNzksImV4cCI6MTcyOTQzNzU3OX0.ZiLSxOJ-iy6YtuhXzWokHMLswsFu4u3716qEJmEkdJc'; -const simpleToken2 = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjE0MjA2MzA1LThiNWMtNDRjYy1iMTc3LTc2NmNmZTJlNDUyZiIsInVzZXJuYW1lIjoicm9vdCIsInR5cGUiOiJ1c2VyIiwiYXVkIjoiYXV0aGVudGljYXRlZCIsInJvbGUiOiJhdXRoZW50aWNhdGVkIiwic3ViIjoiM2Y4MmUzYWUtYjdjMi00MjQ0LTg0OWYtZDQ1M2YzMDRiMmYyIiwiaWF0IjoxNzI5NDE3OTc1LCJleHAiOjE3MzAwMjI3NzV9.niMsxSGuj-iHOY6SUskZwHWXIB9xfhRvpLw1GrqOJLg' +const simpleToken2 = + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjE0MjA2MzA1LThiNWMtNDRjYy1iMTc3LTc2NmNmZTJlNDUyZiIsInVzZXJuYW1lIjoicm9vdCIsInR5cGUiOiJ1c2VyIiwiYXVkIjoiYXV0aGVudGljYXRlZCIsInJvbGUiOiJhdXRoZW50aWNhdGVkIiwic3ViIjoiM2Y4MmUzYWUtYjdjMi00MjQ0LTg0OWYtZDQ1M2YzMDRiMmYyIiwiaWF0IjoxNzI5NDE3OTc1LCJleHAiOjE3MzAwMjI3NzV9.niMsxSGuj-iHOY6SUskZwHWXIB9xfhRvpLw1GrqOJLg'; const client = await supabase.auth.setSession({ access_token: simpleToken2, refresh_token: simpleToken2, diff --git a/src/login.ts b/src/login.ts index a5f3401..9c91080 100644 --- a/src/login.ts +++ b/src/login.ts @@ -1,7 +1,33 @@ -import { supabase } from './module/supabase'; +import { supabase, supabaseServer } from './module/supabase'; const u = await supabase.auth.signInWithPassword({ - email: 'admin@zxj.im', - password: '123456xx', + // email: 'xiongxiao@xiongxiao.me', + phone: '15202829140', + password: process.env.PASSWORD!, }); -console.log('u', u); \ No newline at end of file +console.log('u', u); +await supabaseServer.auth.signInWithPassword +// const isAdmin = await supabaseServer.auth.admin.listUsers(); +// console.log('isAdmin', isAdmin); + +// const admin = await supabase.auth.signInWithPassword({ +// email: 'admin@example.com', +// password: process.env.ADMIN_PASSWORD!, +// }) + +// console.log('admin', admin); +// const { data: test, error } = await supabase.from('test').select('*'); + +// console.log('test', test, error); + +// const res = await supabaseServer.auth.admin.createUser({ +// user_metadata: { full_name: 'Xiongxiao' }, + +// phone: '15202829140', +// password: process.env.PASSWORD!, +// phone_confirm: true, +// }); +// await supabaseServer.auth.admin.updateUserById('fac6fbbd-e8e4-42d9-adbf-b7b2bd008892', { +// phone_confirm: true, +// }); +// console.log('res', res); diff --git a/src/module/supabase.ts b/src/module/supabase.ts index 660c3f7..6a38f09 100644 --- a/src/module/supabase.ts +++ b/src/module/supabase.ts @@ -1,21 +1,20 @@ import { QueryResult, QueryData, QueryError } from '@supabase/supabase-js'; +import dotenv from 'dotenv'; +dotenv.config(); import { createClient, AuthClient } from '@supabase/supabase-js'; // const url = 'http://192.168.31.220:8000' // const url = 'http://supabase.xiongxiao.me' -const url = 'http://supabase.xiongxiao.me'; +// const url = 'http://supabase.xiongxiao.me'; +const url = 'https://base.kevisual.cn'; // const authClient = new AuthClient({ url: url }); -// // const auth = await authClient.signInWithPassword({ email: 'xiongxiao1012@outlook.com', password:'123456xx' }); -// // const auth = await authClient.signInWithPassword({ email: 'admin@zxj.im', password:'123456xx' }); // const auth = await authClient.signInAnonymously(); // console.log('auth', auth); // Create a single supabase client for interacting with your database -const publicAnonKey = - 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.ewogICJyb2xlIjogImFub24iLAogICJpc3MiOiAic3VwYWJhc2UiLAogICJpYXQiOiAxNzI4NTc2MDAwLAogICJleHAiOiAxODg2MzQyNDAwCn0._O6nSz8km61C76qGnRMa44e4sou1qCRBhy8O0riHQmM'; -const serverKey = - 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.ewogICJyb2xlIjogInNlcnZpY2Vfcm9sZSIsCiAgImlzcyI6ICJzdXBhYmFzZSIsCiAgImlhdCI6IDE3Mjg1NzYwMDAsCiAgImV4cCI6IDE4ODYzNDI0MDAKfQ.J9TQ7GUTbh7bKOXCyC1FWiJMrAEzGuJaMGHZZSiIG58'; +const publicAnonKey = process.env.PUBLIC_ANON_KEY!; +const serverKey = process.env.SERVER_KEY!; export const supabase = createClient(url, publicAnonKey); export const supabaseServer = createClient(url, serverKey); diff --git a/src/pg.ts b/src/pg.ts index 0ff3cde..a512836 100644 --- a/src/pg.ts +++ b/src/pg.ts @@ -4,8 +4,8 @@ import pg from 'pg'; // postgres: { // username: 'root', // host: 'light.xiongxiao.me', -// database: 'xpostgres', -// password: 'abearxiong', +// database: 'postgres', +// password: '', // port: 5432, // }, @@ -13,31 +13,10 @@ const pool = new pg.Pool({ user: 'postgres', host: '124.222.140.199', database: 'postgres', - password: '123456xx', + password: process.env.PASSWORD!, port: 5434, }); pool.query('SELECT NOW()', (err, res) => { console.log(err, res); pool.end(); }); - -// 配置数据库连接信息 -// const client = new pg.Client({ -// connectionString: 'postgresql://postgres:123456xx@light.xiongxiao.me:5434/postgres', -// }); - -// // 连接到数据库 -// client.connect() -// .then(() => { -// console.log('Connected to the PostgreSQL database successfully!'); -// return client.query('SELECT NOW()'); // 示例查询 -// }) -// .then((res) => { -// console.log('Server time:', res.rows[0]); -// }) -// .catch((err) => { -// console.error('Database connection error:', err.stack); -// }) -// .finally(() => { -// client.end(); // 关闭数据库连接 -// }); \ No newline at end of file diff --git a/src/send.ts b/src/send.ts index f58a74a..875996e 100644 --- a/src/send.ts +++ b/src/send.ts @@ -1,5 +1,6 @@ import nodemailer from 'nodemailer'; - +import dotenv from 'dotenv'; +dotenv.config(); // 创建传输器(transporter)对象 const transporter = nodemailer.createTransport({ host: 'smtp.feishu.cn', // 替换为你的SMTP服务器地址 @@ -7,7 +8,7 @@ const transporter = nodemailer.createTransport({ secure: false, // 使用TLS协议,false表示不强制加密连接(可根据需求调整) auth: { user: 'root@xiongxiao.me', // 替换为你的邮箱账号 - pass: 'K4fyaHkXTiVZGanV', // 替换为你的邮箱密码 + pass: process.env.EMAIL_PASSWORD, // 替换为你的邮箱密码 }, });