forked from 409/chat-app-frontend
auth
This commit is contained in:
@@ -1,14 +1,23 @@
|
||||
import type { Actions } from '@sveltejs/kit';
|
||||
|
||||
const BACKEND_URL: string = 'http://127.0.0.1:3000' as const;
|
||||
import { fail, type Actions } from '@sveltejs/kit';
|
||||
import { PUBLIC_BACKEND_URL } from '$env/static/public';
|
||||
import { AUTH_COOIKIE_NAME } from '$lib/auth';
|
||||
|
||||
export const actions = {
|
||||
'send-message': async ({request, fetch}) => {
|
||||
'send-message': async ({ request, fetch, cookies }) => {
|
||||
const authToken = cookies.get(AUTH_COOIKIE_NAME);
|
||||
|
||||
if (authToken == null) {
|
||||
return fail(400);
|
||||
}
|
||||
|
||||
const formData = await request.formData();
|
||||
|
||||
const response = await fetch(`${BACKEND_URL}/message`, {
|
||||
const response = await fetch(`${PUBLIC_BACKEND_URL}/message`, {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
headers: {
|
||||
authorization: `Bearer ${authToken}`
|
||||
},
|
||||
body: formData
|
||||
});
|
||||
},
|
||||
}
|
||||
} satisfies Actions;
|
||||
|
||||
Reference in New Issue
Block a user