0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-20 21:32:31 -05:00

feat: passcode table (#198)

* feat: passcode table

* fix: consumed
This commit is contained in:
Wang Sijie 2022-01-26 15:32:03 +08:00 committed by GitHub
parent 5c428efa78
commit 6fadd4a420
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 90 additions and 0 deletions

View file

@ -5,6 +5,11 @@ export enum ApplicationType {
SPA = 'SPA',
Traditional = 'Traditional',
}
export enum PasscodeType {
SignIn = 'SignIn',
Register = 'Register',
ForgotPassword = 'ForgotPassword',
}
export enum UserLogType {
SignInUsernameAndPassword = 'SignInUsernameAndPassword',
ExchangeAccessToken = 'ExchangeAccessToken',

View file

@ -4,6 +4,7 @@ export * from './custom-types';
export * from './application';
export * from './connector';
export * from './oidc-model-instance';
export * from './passcode';
export * from './resource-scope';
export * from './resource';
export * from './setting';

View file

@ -0,0 +1,70 @@
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
import { z } from 'zod';
import { GeneratedSchema, Guard } from '../foundations';
import { PasscodeType } from './custom-types';
export type CreatePasscode = {
id: string;
sessionId: string;
phone?: string | null;
email?: string | null;
type: PasscodeType;
code: string;
consumed?: boolean;
tryCount?: number;
createdAt?: number;
};
export type Passcode = {
id: string;
sessionId: string;
phone: string | null;
email: string | null;
type: PasscodeType;
code: string;
consumed: boolean;
tryCount: number;
createdAt: number;
};
const createGuard: Guard<CreatePasscode> = z.object({
id: z.string(),
sessionId: z.string(),
phone: z.string().nullable().optional(),
email: z.string().nullable().optional(),
type: z.nativeEnum(PasscodeType),
code: z.string(),
consumed: z.boolean().optional(),
tryCount: z.number().optional(),
createdAt: z.number().optional(),
});
export const Passcodes: GeneratedSchema<CreatePasscode> = Object.freeze({
table: 'passcodes',
tableSingular: 'passcode',
fields: {
id: 'id',
sessionId: 'session_id',
phone: 'phone',
email: 'email',
type: 'type',
code: 'code',
consumed: 'consumed',
tryCount: 'try_count',
createdAt: 'created_at',
},
fieldKeys: [
'id',
'sessionId',
'phone',
'email',
'type',
'code',
'consumed',
'tryCount',
'createdAt',
],
createGuard,
});

View file

@ -0,0 +1,14 @@
create type passcode_type as enum ('SignIn', 'Register', 'ForgotPassword');
create table passcodes (
id varchar(128) not null,
session_id varchar(128) not null,
phone varchar(32),
email varchar(128),
type passcode_type not null,
code varchar(6) not null,
consumed boolean not null default FALSE,
try_count int2 not null default 0,
created_at timestamptz not null default(now()),
primary key (id)
);