mirror of
https://github.com/BradNut/TofuStack
synced 2025-09-08 17:40:26 +00:00
moved dto's out of server folder.
This commit is contained in:
parent
ed50dc25f3
commit
e512fab9f9
16 changed files with 21 additions and 153 deletions
|
|
@ -1,23 +1,5 @@
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
|
||||||
/* DTO */
|
|
||||||
/* -------------------------------------------------------------------------- */
|
|
||||||
/* -------------------------------------------------------------------------- */
|
|
||||||
/* ---------------------------------- About --------------------------------- */
|
|
||||||
/*
|
|
||||||
Data Transfer Objects (DTOs) are used to define the shape of data that is passed.
|
|
||||||
They are used to validate data and ensure that the correct data is being passed
|
|
||||||
to the correct methods.
|
|
||||||
*/
|
|
||||||
/* ---------------------------------- Notes --------------------------------- */
|
|
||||||
/*
|
|
||||||
DTO's are pretty flexible. You can use them anywhere you want in this application to
|
|
||||||
validate or shape data. They are especially useful in API routes and services to
|
|
||||||
ensure that the correct data is being passed around.
|
|
||||||
*/
|
|
||||||
/* -------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
export const registerEmailDto = z.object({
|
export const registerEmailDto = z.object({
|
||||||
email: z.string().email()
|
email: z.string().email()
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,5 @@
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
|
||||||
/* DTO */
|
|
||||||
/* -------------------------------------------------------------------------- */
|
|
||||||
/* -------------------------------------------------------------------------- */
|
|
||||||
/* ---------------------------------- About --------------------------------- */
|
|
||||||
/*
|
|
||||||
Data Transfer Objects (DTOs) are used to define the shape of data that is passed.
|
|
||||||
They are used to validate data and ensure that the correct data is being passed
|
|
||||||
to the correct methods.
|
|
||||||
*/
|
|
||||||
/* ---------------------------------- Notes --------------------------------- */
|
|
||||||
/*
|
|
||||||
DTO's are pretty flexible. You can use them anywhere you want in this application to
|
|
||||||
validate or shape data. They are especially useful in API routes and services to
|
|
||||||
ensure that the correct data is being passed around.
|
|
||||||
*/
|
|
||||||
/* -------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
export const signInEmailDto = z.object({
|
export const signInEmailDto = z.object({
|
||||||
email: z.string().email(),
|
email: z.string().email(),
|
||||||
token: z.string()
|
token: z.string()
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,5 @@
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
|
||||||
/* DTO */
|
|
||||||
/* -------------------------------------------------------------------------- */
|
|
||||||
/* -------------------------------------------------------------------------- */
|
|
||||||
/* ---------------------------------- About --------------------------------- */
|
|
||||||
/*
|
|
||||||
Data Transfer Objects (DTOs) are used to define the shape of data that is passed.
|
|
||||||
They are used to validate data and ensure that the correct data is being passed
|
|
||||||
to the correct methods.
|
|
||||||
*/
|
|
||||||
/* ---------------------------------- Notes --------------------------------- */
|
|
||||||
/*
|
|
||||||
DTO's are pretty flexible. You can use them anywhere you want in this application to
|
|
||||||
validate or shape data. They are especially useful in API routes and services to
|
|
||||||
ensure that the correct data is being passed around.
|
|
||||||
*/
|
|
||||||
/* -------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
export const updateEmailDto = z.object({
|
export const updateEmailDto = z.object({
|
||||||
email: z.string().email()
|
email: z.string().email()
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,5 @@
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
|
||||||
/* DTO */
|
|
||||||
/* -------------------------------------------------------------------------- */
|
|
||||||
/* -------------------------------------------------------------------------- */
|
|
||||||
/* ---------------------------------- About --------------------------------- */
|
|
||||||
/*
|
|
||||||
Data Transfer Objects (DTOs) are used to define the shape of data that is passed.
|
|
||||||
They are used to validate data and ensure that the correct data is being passed
|
|
||||||
to the correct methods.
|
|
||||||
*/
|
|
||||||
/* ---------------------------------- Notes --------------------------------- */
|
|
||||||
/*
|
|
||||||
DTO's are pretty flexible. You can use them anywhere you want in this application to
|
|
||||||
validate or shape data. They are especially useful in API routes and services to
|
|
||||||
ensure that the correct data is being passed around.
|
|
||||||
*/
|
|
||||||
/* -------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
export const verifyEmailDto = z.object({
|
export const verifyEmailDto = z.object({
|
||||||
token: z.string()
|
token: z.string()
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
import { Hono } from 'hono';
|
|
||||||
import type { BlankSchema } from 'hono/types';
|
|
||||||
import type { HonoTypes } from '../types/hono.type';
|
|
||||||
|
|
||||||
// export interface Controller {
|
|
||||||
// routes()
|
|
||||||
// }
|
|
||||||
|
|
@ -1,6 +1,3 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export interface Email {
|
export interface Email {
|
||||||
subject(): string
|
subject(): string
|
||||||
html(): string;
|
html(): string;
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,13 @@ import { inject, injectable } from 'tsyringe';
|
||||||
import { zValidator } from '@hono/zod-validator';
|
import { zValidator } from '@hono/zod-validator';
|
||||||
import { IamService } from '../services/iam.service';
|
import { IamService } from '../services/iam.service';
|
||||||
import { LuciaProvider } from '../providers/lucia.provider';
|
import { LuciaProvider } from '../providers/lucia.provider';
|
||||||
import { signInEmailDto } from '../../../dtos/signin-email.dto';
|
|
||||||
import { updateEmailDto } from '../../../dtos/update-email.dto';
|
|
||||||
import { verifyEmailDto } from '../../../dtos/verify-email.dto';
|
|
||||||
import { registerEmailDto } from '../../../dtos/register-email.dto';
|
|
||||||
import { limiter } from '../middlewares/rate-limiter.middlware';
|
import { limiter } from '../middlewares/rate-limiter.middlware';
|
||||||
import { requireAuth } from '../middlewares/auth.middleware';
|
import { requireAuth } from '../middlewares/auth.middleware';
|
||||||
import { Controler } from '../common/classes/controller.class';
|
import { Controler } from '../common/classes/controller.class';
|
||||||
|
import { registerEmailDto } from '$lib/dtos/register-email.dto';
|
||||||
|
import { signInEmailDto } from '$lib/dtos/signin-email.dto';
|
||||||
|
import { updateEmailDto } from '$lib/dtos/update-email.dto';
|
||||||
|
import { verifyEmailDto } from '$lib/dtos/verify-email.dto';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class IamController extends Controler {
|
export class IamController extends Controler {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
import { z } from 'zod';
|
|
||||||
|
|
||||||
export const registerEmailDto = z.object({
|
|
||||||
email: z.string().email()
|
|
||||||
});
|
|
||||||
|
|
||||||
export type RegisterEmailDto = z.infer<typeof registerEmailDto>;
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
import { z } from 'zod';
|
|
||||||
|
|
||||||
export const signInEmailDto = z.object({
|
|
||||||
email: z.string().email(),
|
|
||||||
token: z.string()
|
|
||||||
});
|
|
||||||
|
|
||||||
export type SignInEmailDto = z.infer<typeof signInEmailDto>;
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
import { z } from 'zod';
|
|
||||||
|
|
||||||
export const updateEmailDto = z.object({
|
|
||||||
email: z.string().email()
|
|
||||||
});
|
|
||||||
export type UpdateEmailDto = z.infer<typeof updateEmailDto>;
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
import { z } from 'zod';
|
|
||||||
|
|
||||||
export const verifyEmailDto = z.object({
|
|
||||||
token: z.string()
|
|
||||||
});
|
|
||||||
export type VerifyEmailDto = z.infer<typeof verifyEmailDto>;
|
|
||||||
|
|
@ -1,15 +1,15 @@
|
||||||
import { inject, injectable } from "tsyringe";
|
import { inject, injectable } from "tsyringe";
|
||||||
import { JobsService } from "../services/jobs.service";
|
import { JobsService } from "../services/jobs.service";
|
||||||
|
|
||||||
|
// Example on how to create a job that runs once a week at midnight on Sunday
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class AuthCleanupJobs {
|
export class AuthCleanupJobs {
|
||||||
private queue;
|
private queue;
|
||||||
|
|
||||||
constructor(
|
constructor(@inject(JobsService) private jobsService: JobsService) {
|
||||||
@inject(JobsService) private jobsService: JobsService,
|
|
||||||
) {
|
|
||||||
/* ------------------------------ Create Queue ------------------------------ */
|
/* ------------------------------ Create Queue ------------------------------ */
|
||||||
this.queue = this.jobsService.createQueue('test')
|
this.queue = this.jobsService.createQueue('auth_cleanup')
|
||||||
|
|
||||||
/* ---------------------------- Register Workers ---------------------------- */
|
/* ---------------------------- Register Workers ---------------------------- */
|
||||||
this.worker();
|
this.worker();
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ import { MailerService } from './mailer.service';
|
||||||
import { TokensService } from './tokens.service';
|
import { TokensService } from './tokens.service';
|
||||||
import { LuciaProvider } from '../providers/lucia.provider';
|
import { LuciaProvider } from '../providers/lucia.provider';
|
||||||
import { UsersRepository } from '../repositories/users.repository';
|
import { UsersRepository } from '../repositories/users.repository';
|
||||||
import type { SignInEmailDto } from '../dtos/signin-email.dto';
|
import type { SignInEmailDto } from '../../../dtos/signin-email.dto';
|
||||||
import type { RegisterEmailDto } from '../dtos/register-email.dto';
|
import type { RegisterEmailDto } from '../../../dtos/register-email.dto';
|
||||||
import { LoginRequestsRepository } from '../repositories/login-requests.repository';
|
import { LoginRequestsRepository } from '../repositories/login-requests.repository';
|
||||||
import { LoginVerificationEmail } from '../emails/login-verification.email';
|
import { LoginVerificationEmail } from '../emails/login-verification.email';
|
||||||
import { DatabaseProvider } from '../providers/database.provider';
|
import { DatabaseProvider } from '../providers/database.provider';
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,7 @@ import { RedisProvider } from "../providers/redis.provider";
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class JobsService {
|
export class JobsService {
|
||||||
constructor(@inject(RedisProvider) private readonly redis: RedisProvider) {
|
constructor(@inject(RedisProvider) private readonly redis: RedisProvider) { }
|
||||||
}
|
|
||||||
|
|
||||||
createQueue(name: string) {
|
createQueue(name: string) {
|
||||||
return new Queue(name, { connection: this.redis })
|
return new Queue(name, { connection: this.redis })
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
import { fail, redirect } from '@sveltejs/kit';
|
import { fail, redirect } from '@sveltejs/kit';
|
||||||
import { zod } from 'sveltekit-superforms/adapters';
|
import { zod } from 'sveltekit-superforms/adapters';
|
||||||
import { signInEmailDto } from '$lib/dtos/signin-email.dto.js';
|
|
||||||
import { setError, superValidate } from 'sveltekit-superforms';
|
|
||||||
import { registerEmailDto } from '$lib/dtos/register-email.dto.js';
|
|
||||||
import { StatusCodes } from '$lib/constants/status-codes';
|
import { StatusCodes } from '$lib/constants/status-codes';
|
||||||
|
import { registerEmailDto } from '$lib/dtos/register-email.dto';
|
||||||
|
import { signInEmailDto } from '$lib/dtos/signin-email.dto';
|
||||||
|
import { setError, superValidate } from 'sveltekit-superforms';
|
||||||
|
|
||||||
export const load = async () => {
|
export const load = async () => {
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -1,36 +1,15 @@
|
||||||
<!-- <script>
|
|
||||||
import { enhance } from '$app/forms';
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<h3>Register</h3>
|
|
||||||
<form action="?/register" method="POST" use:enhance>
|
|
||||||
<label for="email">Email</label>
|
|
||||||
<input name="email" type="email" />
|
|
||||||
<button type="submit">Register</button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<h3>Verify</h3>
|
|
||||||
<form action="?/signin" method="POST" use:enhance>
|
|
||||||
<label for="email">Email</label>
|
|
||||||
<input name="email" type="email" />
|
|
||||||
<label for="token">Token</label>
|
|
||||||
<input name="token" type="text" />
|
|
||||||
<button type="submit">Login</button>
|
|
||||||
</form> -->
|
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Button } from "$lib/components/ui/button/index.js";
|
import { Button } from '$lib/components/ui/button/index.js';
|
||||||
import * as Card from "$lib/components/ui/card/index.js";
|
import * as Card from '$lib/components/ui/card/index.js';
|
||||||
import { Input } from "$lib/components/ui/input/index.js";
|
import { Input } from '$lib/components/ui/input/index.js';
|
||||||
import { Label } from "$lib/components/ui/label/index.js";
|
|
||||||
import { superForm } from 'sveltekit-superforms';
|
import { superForm } from 'sveltekit-superforms';
|
||||||
import * as Form from '$lib/components/ui/form';
|
import * as Form from '$lib/components/ui/form';
|
||||||
import { zodClient } from 'sveltekit-superforms/adapters';
|
import { zodClient } from 'sveltekit-superforms/adapters';
|
||||||
import { registerEmailDto } from "$lib/dtos/register-email.dto.js";
|
import { registerEmailDto } from '$lib/dtos/register-email.dto.js';
|
||||||
import { signInEmailDto } from "$lib/dtos/signin-email.dto.js";
|
import { signInEmailDto } from '$lib/dtos/signin-email.dto.js';
|
||||||
import PinInput from "$lib/components/pin-input.svelte";
|
import PinInput from '$lib/components/pin-input.svelte';
|
||||||
|
|
||||||
const {data} = $props();
|
const { data } = $props();
|
||||||
|
|
||||||
let showTokenVerification = $state(false);
|
let showTokenVerification = $state(false);
|
||||||
|
|
||||||
|
|
@ -52,7 +31,6 @@
|
||||||
|
|
||||||
const { form: emailRegisterFormData, enhance: emailRegisterEnhance } = emailRegisterForm;
|
const { form: emailRegisterFormData, enhance: emailRegisterEnhance } = emailRegisterForm;
|
||||||
const { form: emailSigninFormData, enhance: emailSigninEnhance } = emailSigninForm;
|
const { form: emailSigninFormData, enhance: emailSigninEnhance } = emailSigninForm;
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Card.Root class="mx-auto mt-24 max-w-sm">
|
<Card.Root class="mx-auto mt-24 max-w-sm">
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue