@@ -2,17 +2,19 @@ import { error, fail, redirect } from '@sveltejs/kit';
22import { superValidate } from 'sveltekit-superforms/server' ;
33import { zod } from 'sveltekit-superforms/adapters' ;
44
5- import { getLoggedInUser } from '$lib/utils/authorship' ;
65import { workBookSchema } from '$lib/zod/schema' ;
6+
77import * as workBooksCrud from '$lib/services/workbooks' ;
8+ import * as tasksCrud from '$lib/services/tasks' ;
9+
810import { Roles } from '$lib/types/user' ;
9- import type { WorkBook } from '$lib/types/workbook' ;
11+
12+ import { getLoggedInUser } from '$lib/utils/authorship' ;
1013import {
1114 BAD_REQUEST ,
1215 FORBIDDEN ,
1316 TEMPORARY_REDIRECT ,
1417} from '$lib/constants/http-response-status-codes' ;
15- import * as tasksCrud from '$lib/services/tasks' ;
1618
1719export const load = async ( { locals } ) => {
1820 // ログインしていない場合は、ログイン画面へ遷移させる
@@ -39,7 +41,12 @@ export const load = async ({ locals }) => {
3941export const actions = {
4042 default : async ( { locals, request } ) => {
4143 console . log ( 'form -> actions -> create' ) ;
42- await getLoggedInUser ( locals ) ;
44+ const author = await getLoggedInUser ( locals ) ;
45+
46+ if ( ! author ) {
47+ return fail ( FORBIDDEN , { message : 'ログインが必要です。' } ) ;
48+ }
49+
4350 const form = await superValidate ( request , zod ( workBookSchema ) ) ;
4451
4552 if ( ! form . valid ) {
@@ -52,7 +59,11 @@ export const actions = {
5259 } ) ;
5360 }
5461
55- const workBook : WorkBook = form . data ;
62+ // Note: form.data includes authorId
63+ const workBook = {
64+ ...form . data ,
65+ id : 0 , // Dummy id (Prisma will auto-generate it)
66+ } ;
5667
5768 try {
5869 await workBooksCrud . createWorkBook ( workBook ) ;
0 commit comments