feat: remove supabase
This commit is contained in:
parent
ce6037ead9
commit
1616177026
@ -38,7 +38,6 @@
|
|||||||
"@kevisual/ai-lang": "workspace:^",
|
"@kevisual/ai-lang": "workspace:^",
|
||||||
"@kevisual/auth": "1.0.4",
|
"@kevisual/auth": "1.0.4",
|
||||||
"@kevisual/router": "0.0.5",
|
"@kevisual/router": "0.0.5",
|
||||||
"@supabase/supabase-js": "^2.46.1",
|
|
||||||
"@types/semver": "^7.5.8",
|
"@types/semver": "^7.5.8",
|
||||||
"archiver": "^7.0.1",
|
"archiver": "^7.0.1",
|
||||||
"bullmq": "^5.29.0",
|
"bullmq": "^5.29.0",
|
||||||
|
@ -16,6 +16,7 @@ type UserData = {
|
|||||||
export class User extends Model {
|
export class User extends Model {
|
||||||
declare id: string;
|
declare id: string;
|
||||||
declare username: string;
|
declare username: string;
|
||||||
|
declare nickname: string; // 昵称
|
||||||
declare password: string;
|
declare password: string;
|
||||||
declare salt: string;
|
declare salt: string;
|
||||||
declare needChangePassword: boolean;
|
declare needChangePassword: boolean;
|
||||||
@ -26,29 +27,20 @@ export class User extends Model {
|
|||||||
declare orgId: string;
|
declare orgId: string;
|
||||||
declare email: string;
|
declare email: string;
|
||||||
declare avatar: string;
|
declare avatar: string;
|
||||||
declare supaId: string;
|
|
||||||
tokenUser: any;
|
tokenUser: any;
|
||||||
setTokenUser(tokenUser: any) {
|
setTokenUser(tokenUser: any) {
|
||||||
this.tokenUser = tokenUser;
|
this.tokenUser = tokenUser;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* uid 是用于 orgId 的用户id
|
* uid 是用于 orgId 的用户id 真实用户的id
|
||||||
* @param uid
|
* @param uid
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
async createToken(uid?: string) {
|
async createToken(uid?: string) {
|
||||||
const { id, username, type, supaId } = this;
|
const { id, username, type } = this;
|
||||||
const expireTime = 60 * 60 * 24 * 7; // 7 days
|
const expireTime = 60 * 60 * 24 * 7; // 7 days
|
||||||
const now = new Date().getTime();
|
const now = new Date().getTime();
|
||||||
let supa = {};
|
const token = await createToken({ id, username, uid, type }, config.tokenSecret);
|
||||||
if (supaId) {
|
|
||||||
supa = {
|
|
||||||
aud: 'authenticated',
|
|
||||||
role: 'authenticated',
|
|
||||||
sub: supaId,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
const token = await createToken({ id, username, uid, type, ...supa }, config.tokenSecret);
|
|
||||||
return { token, expireTime: now + expireTime };
|
return { token, expireTime: now + expireTime };
|
||||||
}
|
}
|
||||||
static async verifyToken(token: string) {
|
static async verifyToken(token: string) {
|
||||||
@ -155,6 +147,12 @@ User.init(
|
|||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
unique: true,
|
unique: true,
|
||||||
|
// 用户名或者手机号
|
||||||
|
// 创建后避免修改的字段,当注册用户后,用户名注册则默认不能用手机号
|
||||||
|
},
|
||||||
|
nickname: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
allowNull: true,
|
||||||
},
|
},
|
||||||
password: {
|
password: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
@ -165,7 +163,7 @@ User.init(
|
|||||||
allowNull: true,
|
allowNull: true,
|
||||||
},
|
},
|
||||||
avatar: {
|
avatar: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.TEXT,
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
},
|
},
|
||||||
salt: {
|
salt: {
|
||||||
@ -173,7 +171,7 @@ User.init(
|
|||||||
allowNull: true,
|
allowNull: true,
|
||||||
},
|
},
|
||||||
description: {
|
description: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.TEXT,
|
||||||
},
|
},
|
||||||
type: {
|
type: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
@ -185,9 +183,6 @@ User.init(
|
|||||||
orgId: {
|
orgId: {
|
||||||
type: DataTypes.UUID,
|
type: DataTypes.UUID,
|
||||||
},
|
},
|
||||||
supaId: {
|
|
||||||
type: DataTypes.UUID,
|
|
||||||
},
|
|
||||||
needChangePassword: {
|
needChangePassword: {
|
||||||
type: DataTypes.BOOLEAN,
|
type: DataTypes.BOOLEAN,
|
||||||
defaultValue: false,
|
defaultValue: false,
|
||||||
@ -199,7 +194,7 @@ User.init(
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
sequelize,
|
sequelize,
|
||||||
tableName: 'cf_user',
|
tableName: 'cf_user', // codeflow user
|
||||||
paranoid: true,
|
paranoid: true,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -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,
|
|
||||||
});
|
|
@ -1,4 +1,4 @@
|
|||||||
import { Snippet } from '@/models-supa/snippet.ts';
|
import { Snippet } from '@/routes/snippet/snippet.ts';
|
||||||
import { app } from '@/app.ts';
|
import { app } from '@/app.ts';
|
||||||
|
|
||||||
app
|
app
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { sequelize } from '@/modules/sequelize-supa.ts';
|
import { sequelize } from '@/modules/sequelize.ts';
|
||||||
import { DataTypes, Model } from 'sequelize';
|
import { DataTypes, Model } from 'sequelize';
|
||||||
|
|
||||||
export class Snippet extends Model {
|
export class Snippet extends Model {
|
@ -1,4 +1,4 @@
|
|||||||
import { Snippet } from '@/models-supa/snippet.ts';
|
import { Snippet } from '@/routes/snippet/snippet.ts';
|
||||||
|
|
||||||
const main = async () => {
|
const main = async () => {
|
||||||
const snippet = await Snippet.findAndCountAll();
|
const snippet = await Snippet.findAndCountAll();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user