feat: remove supabase

This commit is contained in:
xion 2024-11-28 21:08:27 +08:00
parent ce6037ead9
commit 1616177026
6 changed files with 16 additions and 48 deletions

View File

@ -38,7 +38,6 @@
"@kevisual/ai-lang": "workspace:^",
"@kevisual/auth": "1.0.4",
"@kevisual/router": "0.0.5",
"@supabase/supabase-js": "^2.46.1",
"@types/semver": "^7.5.8",
"archiver": "^7.0.1",
"bullmq": "^5.29.0",

View File

@ -16,6 +16,7 @@ type UserData = {
export class User extends Model {
declare id: string;
declare username: string;
declare nickname: string; // 昵称
declare password: string;
declare salt: string;
declare needChangePassword: boolean;
@ -26,29 +27,20 @@ export class User extends Model {
declare orgId: string;
declare email: string;
declare avatar: string;
declare supaId: string;
tokenUser: any;
setTokenUser(tokenUser: any) {
this.tokenUser = tokenUser;
}
/**
* uid orgId id
* uid orgId id id
* @param uid
* @returns
*/
async createToken(uid?: string) {
const { id, username, type, supaId } = this;
const { id, username, type } = this;
const expireTime = 60 * 60 * 24 * 7; // 7 days
const now = new Date().getTime();
let supa = {};
if (supaId) {
supa = {
aud: 'authenticated',
role: 'authenticated',
sub: supaId,
};
}
const token = await createToken({ id, username, uid, type, ...supa }, config.tokenSecret);
const token = await createToken({ id, username, uid, type }, config.tokenSecret);
return { token, expireTime: now + expireTime };
}
static async verifyToken(token: string) {
@ -155,6 +147,12 @@ User.init(
type: DataTypes.STRING,
allowNull: false,
unique: true,
// 用户名或者手机号
// 创建后避免修改的字段,当注册用户后,用户名注册则默认不能用手机号
},
nickname: {
type: DataTypes.TEXT,
allowNull: true,
},
password: {
type: DataTypes.STRING,
@ -165,7 +163,7 @@ User.init(
allowNull: true,
},
avatar: {
type: DataTypes.STRING,
type: DataTypes.TEXT,
allowNull: true,
},
salt: {
@ -173,7 +171,7 @@ User.init(
allowNull: true,
},
description: {
type: DataTypes.STRING,
type: DataTypes.TEXT,
},
type: {
type: DataTypes.STRING,
@ -185,9 +183,6 @@ User.init(
orgId: {
type: DataTypes.UUID,
},
supaId: {
type: DataTypes.UUID,
},
needChangePassword: {
type: DataTypes.BOOLEAN,
defaultValue: false,
@ -199,7 +194,7 @@ User.init(
},
{
sequelize,
tableName: 'cf_user',
tableName: 'cf_user', // codeflow user
paranoid: true,
},
);

View File

@ -1,26 +0,0 @@
import { useConfig } from '@kevisual/use-config';
import { Sequelize } from 'sequelize';
type PostgresConfig = {
supabaseSQL: {
username: string;
password: string;
host: string;
port: number;
database: string;
};
};
const config = useConfig<PostgresConfig>();
const postgresConfig = config.supabaseSQL;
if (!postgresConfig) {
console.error('postgres config is required');
process.exit(1);
}
// connect to db
export const sequelize = new Sequelize({
dialect: 'postgres',
...postgresConfig,
// logging: false,
});

View File

@ -1,4 +1,4 @@
import { Snippet } from '@/models-supa/snippet.ts';
import { Snippet } from '@/routes/snippet/snippet.ts';
import { app } from '@/app.ts';
app

View File

@ -1,4 +1,4 @@
import { sequelize } from '@/modules/sequelize-supa.ts';
import { sequelize } from '@/modules/sequelize.ts';
import { DataTypes, Model } from 'sequelize';
export class Snippet extends Model {

View File

@ -1,4 +1,4 @@
import { Snippet } from '@/models-supa/snippet.ts';
import { Snippet } from '@/routes/snippet/snippet.ts';
const main = async () => {
const snippet = await Snippet.findAndCountAll();