feat: add snippet and test for supa db
This commit is contained in:
@@ -26,15 +26,29 @@ 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
|
||||
* @param uid
|
||||
* @returns
|
||||
*/
|
||||
async createToken(uid?: string) {
|
||||
const { id, username, type } = this;
|
||||
const { id, username, type, supaId } = this;
|
||||
const expireTime = 60 * 60 * 24 * 7; // 7 days
|
||||
const now = new Date().getTime();
|
||||
const token = await createToken({ id, username, uid, type }, config.tokenSecret);
|
||||
let supa = {};
|
||||
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 };
|
||||
}
|
||||
static async verifyToken(token: string) {
|
||||
@@ -168,6 +182,9 @@ User.init(
|
||||
orgId: {
|
||||
type: DataTypes.UUID,
|
||||
},
|
||||
supaId: {
|
||||
type: DataTypes.UUID,
|
||||
},
|
||||
needChangePassword: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: false,
|
||||
|
||||
Reference in New Issue
Block a user