mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-10 15:35:35 +00:00
feat: add auth via google
This commit is contained in:
@@ -1,30 +1,53 @@
|
||||
import type { GoogleToken } from '@adonisjs/ally/types';
|
||||
import { beforeCreate, column } from '@adonisjs/lucid/orm';
|
||||
import { DateTime } from 'luxon';
|
||||
import hash from '@adonisjs/core/services/hash';
|
||||
import { compose } from '@adonisjs/core/helpers';
|
||||
import { BaseModel, column } from '@adonisjs/lucid/orm';
|
||||
import { withAuthFinder } from '@adonisjs/auth/mixins/lucid';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import AppBaseModel from './app_base_model.js';
|
||||
|
||||
const AuthFinder = withAuthFinder(() => hash.use('scrypt'), {
|
||||
uids: ['email'],
|
||||
passwordColumnName: 'password',
|
||||
});
|
||||
export default class User extends AppBaseModel {
|
||||
static selfAssignPrimaryKey = true;
|
||||
|
||||
export default class User extends compose(BaseModel, AuthFinder) {
|
||||
@column({ isPrimary: true })
|
||||
declare id: number;
|
||||
|
||||
@column()
|
||||
declare fullName: string | null;
|
||||
declare id: string; // UUID
|
||||
|
||||
@column()
|
||||
declare email: string;
|
||||
|
||||
@column()
|
||||
declare password: string;
|
||||
declare name: string;
|
||||
|
||||
@column.dateTime({ autoCreate: true })
|
||||
@column({ serializeAs: 'nickName' })
|
||||
declare nickName: string; // public username
|
||||
|
||||
@column({ serializeAs: 'avatarUrl' })
|
||||
declare avatarUrl: string;
|
||||
|
||||
declare isAdmin: boolean;
|
||||
|
||||
@column({ serializeAs: null })
|
||||
declare token: GoogleToken;
|
||||
|
||||
@column({ serializeAs: null })
|
||||
declare providerId: string;
|
||||
|
||||
@column.dateTime({
|
||||
autoCreate: true,
|
||||
serialize: (value: DateTime) => value.toISODate(),
|
||||
serializeAs: 'createdAt',
|
||||
})
|
||||
declare createdAt: DateTime;
|
||||
|
||||
@column.dateTime({ autoCreate: true, autoUpdate: true })
|
||||
declare updatedAt: DateTime | null;
|
||||
@column.dateTime({
|
||||
autoCreate: true,
|
||||
autoUpdate: true,
|
||||
serialize: (value: DateTime) => value.toISODate(),
|
||||
serializeAs: 'updatedAt',
|
||||
})
|
||||
declare updatedAt: DateTime;
|
||||
|
||||
@beforeCreate()
|
||||
static assignUuid(user: User) {
|
||||
user.id = uuidv4();
|
||||
user.isAdmin = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user