#development

1 messages · Page 234 of 1

quartz kindle
#

do you have any form of server side rendering?

#

or are you using svelte as a compiler to build html files?

sharp geyser
#

ermmmmm

#

idfk

#

😭

#

I mean I have some page.server.ts files

#

that handles form submissions to fetch the apis

#

mainly because superforms requires an action on the server side to handle submissions

quartz kindle
#

if you're using npm run or node for routing then you're using svelte as a server as well

#

therefore you can do serverside rendering

#

which means

#

page.server.js files are run on the server side

#

which means, you can directly fetch data from db in there, if a session exists, and add that to the page data

#

on page load

#

so you dont need to fetch nor store in localstorage

sharp geyser
quartz kindle
#

its like EJS

#

you connect to db and add variables into the html

sharp geyser
#

I have no idea about web dev bro

#

I just knew ejs was cursed

quartz kindle
#

thats why its confusing

#

because frontend and backend are distinct things

#

and svelte can run on both modes

#

frontend only

#

or full stack framework

sharp geyser
#

my thing is

quartz kindle
#

like nextjs and shit

sharp geyser
#

my login endpoint returns the user data of the session

quartz kindle
#

yes

#

only if the user is not logged in

sharp geyser
#

what?

quartz kindle
#

if the user is already logged in

#

then ALL pages can already load with the data already there

#

embedded in the js/html

sharp geyser
#

I do not follow your thought process at all

#

I see no reaso nto connect my frontend to my db

quartz kindle
#

its not frontend

#

its backend

sharp geyser
#

right....

#

I have a backend api

#

its already connected to the db?

quartz kindle
#

in a league game rn brb

sharp geyser
#

ok

frosty gale
#

i have received a notification from this channel

#

who dare disturb chloe's thy inner zen

#

its not that complicated

#

it depends on what you want to do

#

if you want a single app layout (you can switch pages without reloads) you just keep your user states and things to persist in your layout

#

you can import that from any component

#

but in general you should login in the user, then store their details in local storage

#

then you can fetch those details at any time

#

or do things SSR

sharp geyser
#

ys but how

#

Thats what I am confused on

#

the way superforms works what im using for form validation is it requires an action on the server via +page.server.ts to handle the resulting values from it

#

I dont see how I can store something in local storage, from the server

digital swan
#

When you receive data from the server on the client side, what’s stopping you from storing it in local storage

sharp geyser
#

Wdym

#

what data from the server?

digital swan
#

You’re wanting to store user information right?

sharp geyser
#

yes

#

My client submits a form, a server action inside +page.server.ts handles that action, and requests my rust backend api for logging in, which returns the userinformation about that user's session

digital swan
#

Well since you’re using super forms, you can return message(form, <custom data>) from the form action and it’ll be under the message form given by the super forms client side thing

#

Or there’s an onUpdate function you can set in the superforms properties

sharp geyser
#

wym

digital swan
#

Form submit

Runs your server side action which does stuff with your other backend

Return whatever response you want to the client

access via the onUpdate or message store and do whatever you want with it

sharp geyser
#

right but how should I return it?

digital swan
#

return message(form, {anything})

sharp geyser
#
export const actions = {
    default: async ({ request, fetch }) => {
        const form = await superValidate(request, zod(loginSchema))

        let response = await fetch('/api/auth/login', {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            },
            method: 'post',
            body: new URLSearchParams({
                email: form.data.email,
                password: form.data.password
            })
        })

        const data = await response.json()

        return { form, data }

    }
}
```?
digital swan
#

I believe you should use message with super forms

#

Like import their function

digital swan
sharp geyser
#
import { superValidate, message } from 'sveltekit-superforms'
import { zod } from 'sveltekit-superforms/adapters'
import type { PageServerLoad } from './$types'
import { loginSchema } from '$lib'

export const load: PageServerLoad = async () => {
    const form = await superValidate(zod(loginSchema))
    return { form }
}

export const actions = {
    default: async ({ request, fetch }) => {
        const form = await superValidate(request, zod(loginSchema))

        let response = await fetch('/api/auth/login', {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            },
            method: 'post',
            body: new URLSearchParams({
                email: form.data.email,
                password: form.data.password
            })
        })

        const data = await response.json()

        return message(form, { data })

    }
}
```?
digital swan
#

Yes

#

Now you should be able to get the data in your client side through either onUpdate or the message store

sharp geyser
#

icic

#

so then i'd use that to set it to local storage?

digital swan
#

Yes

sharp geyser
#

What about svelte stores?

#

If I use localstorage

#

theres no point in them right?

digital swan
#

Stores aren’t persistent

sharp geyser
#

well yea ik

digital swan
#

If you refresh they’re gone

sharp geyser
#

What I mean is, whats the point of stores then

#

It seems like a useless feature

digital swan
#

To have reactive data across the entire app

sharp geyser
#

but if it goes away after refreshing

#

then theres no point

digital swan
#

They’re meant for use on a spa

#

Where it doesn’t refresh on each navigation

#

There is a package that can use local storage with svelte stores though

sharp geyser
#

what exactly constitues something as an spa?

digital swan
#

Uhhhh

sharp geyser
#

because when I build my svelte app

#

it doesn't refresh on navigation

digital swan
#

I believe it’s when the dom changes with JavaScript instead of it navigating to a different html file

sharp geyser
#

so

#

do I just fetch from local storage each time?

digital swan
#

Well personally I’d say local storage isn’t the way to do it bc it could be invalid/out of date data

sharp geyser
#

you just made me even more confused

#

what the hell was the entire point of this

#

if you are now telling me its not the best idea

digital swan
#

LOL

sharp geyser
#

Like

#

please

digital swan
#

I mean I’m no professional

sharp geyser
#

start with that

#

😔

digital swan
#

But on my sites it’s

#

Page load

Layout onMount fetches auth data from route

Sets data to a store

Then can update the ui accordingly

sharp geyser
#

im fixing to just sell one of my fucking kidneys and hire a frontend dev

#

I cant do this anymore

digital swan
#

I think having the 2 backends confuses it a lot

sharp geyser
#

I just do not fucking understand

#

why does a frontend framework

#

have a backend api

#

ITS FOR FRONTEND

digital swan
#

svelte is the front end

#

Sveltekit is the framework that works with svelte

#

it’s like react and nextjs

sharp geyser
#

yea I know

#

I hate nextjs too

#

because its dumb asf

digital swan
#

I don’t even wanna attempt those

sharp geyser
#

I was using nextjs originally

#

but then I thought "Oh maybe state management is better in svelte"

#

I was fucking wrong

#

Why do frontend frameworks have to make everything more complicated than it needs to be

frosty gale
#

you dont have to use it

#

you can use svelte standalone if you want to

#

thats how it started out anyways

sharp geyser
#

I mean sure

#

but then i'd have to setup routing myself

#

im not hating on sveltekit

#

Im hating on how I have to do this

#

Its more complicated than it needs to be

proven lantern
#

if i replace rust with zig will my build times be faster?

frosty gale
#

and i agree with that you dont have to use the extended features

#

you can disable SSR which basically makes sveltekit a router

#

thats what i did

sharp geyser
#

All I want to do...is just render the person name when they fucking login

#

thats it

sharp geyser
#

to export an action

frosty gale
#

thats understandable

sharp geyser
#

my issue is

frosty gale
#

that library is for users that want to integrate backend and frontends together with sveltekit

#

it defeats the point using it with a different backend

sharp geyser
#

I can't set the state for that user that loggged in on the server or else ANYONE will be able to see that state

#

I mean fair enough

#

but I also don't know how to validate forms myself

#

😔

digital swan
#

Just shout at them if they break it

frosty gale
#

you just define the schema and it verifies the data before it gets passed to your routers

#

ill show you how it looks on mine

sharp geyser
#

ok

frosty gale
#

in this case it expects the data to be:

{ type: either_1_or_2_number, content: string_with_max_length_500, nonce: some_number }
#

if it isnt it will return a nice detailed error message as response

#

if everything fits the schema it continues with the handler below and you dont need to worry about validation anymore

#

theres also libraries which make creating schemas easier

#

i just wanted to define them manually

#

and from the front end i just do a fetch request with the data to the backend

sharp geyser
#

like zod?

frosty gale
#

you can do it with forms too

sharp geyser
#

I use zod for schemas

#
import * as z from 'zod'

export const schema = z.object({
    firstName: z.string().min(1, "is invalid"),
    lastName: z.string().min(1, "is invalid"),
    email: z.string().email("is invalid"),
    password: z.string().min(8, "minimum 8 characters"),
    passwordConfirmation: z.string()
}).required().refine((data) => data.password === data.passwordConfirmation, {
    message: 'doesn\'t match',
    path: ['passwordConfirmation']
})

export const loginSchema = z.object({
    email: z.string().email("is invalid"),
    password: z.string().min(8, "minimum 8 characters")
}).required()
frosty gale
#

that works too

#

the backend will verify the incoming data

#

and if anything goes wrong add a handler for the frontend form error

#

so you can display an error or whatever

sharp geyser
#

hm

#

I thought the entire point of client-side validation errors, was to mitigate problems before they start

#

why delgate ALL the work to the backend?

#

sure the backend should still check

lament rock
#

Authority is the main concern. People can easily forget if they assume the client will do all the heavy lifting

frosty gale
#

you should do client-side validation too but youd have to do them separate

#

its quite easy to add for forms

lament rock
#

client side validation is only useful if you want to avoid unnecessary traffic

#

Such as in cases of rate limits

#

Depending on how complex the inner logic of the validation is, it could just be free basically

frosty gale
sharp geyser
#

well yes

#

I wasn't saying not to

#

I was wondering why put all the heavy lifting on the backend

#

ofc someone can decide to manually hit it without the form so you should do validations server side as well

frosty gale
#

a lot of people do it because its easier and it doesnt really affect the server all that much when it comes to traffic
but you should do client side verification too to provide instant feedback and not request server unnecessarily

#

but if you do or dont its not a big deal

sharp geyser
#

right

#

Also what even is the point of SSR

#

Im not big into web dev

lament rock
#

SSR?

sharp geyser
#

Server Side Rendering ig is what you guys call it

digital swan
#

Better for SEO and quicker than client side rendering

lament rock
#

You need to do some SSR for stuff like X Site Request Forgery tokens

sharp geyser
#

so you can't disable it outright?

lament rock
#

You shouldnt for forms or any actions that create/modify/delete data

#

xsrf is really important to defend against

frosty gale
#

modern browsers have a lot of security headers and prevention measures you can use now instead

#

or by being smart with how you construct your app and api calls

lament rock
#

🤐 That's an L excuse since older browsers still exist. More security holes

frosty gale
frosty gale
sharp geyser
#

ong

#

thats how I feel

frosty gale
#

same as using an outdated operating system

#

youre asking for security holes anyways

sharp geyser
#

I cant guard your stupidity

lament rock
#

The US government still uses an older Windows version because modern ones are less stable

sharp geyser
#

ima be real

lament rock
#

But whatever. You problem to solve

sharp geyser
#

who cares about the us gov

#

if they are using my app on their systems, then they are already done for

frosty gale
sharp geyser
#

Also, if we are to believe those iso leaks for the gov edition of windows, then they have virtually nothing on them anyway, and while it may have been for the chinese gov, the US definitely emplores similar conditions

#

cant even get a browser on it

lament rock
#

I think the main thing is getting used to the workflow when you branch out to other endeavors unrelated to what you're working on and is meant to be more widely adopted. Will you allow your laziness to prevent you from guarding against shit like that or will you get serious. Even if you do get serious, more research

frosty gale
#

it takes too much time maintaining support for older software which means less time to focus on things that matter

frosty gale
#

you wouldnt be able to access them from the outside

#

itd be too much of a risk even with security updates doing that with front facing servers

#

im not sure though since i havent worked on government related projects

#

you need to get top security clearance to touch any government resources and i didnt bother with it really

#

some colleagues did though but well cant tell me

sharp geyser
#

what does on:submit return

#

I looked at the interweb and it tells me a EventHandler<HTMLFormEvent> or smth

frosty gale
sharp geyser
#

im trying

#

but since im using ts

#

the param takes a type

#

idk what type to give it

frosty gale
#

type for what

#

the param for the on submit event?

sharp geyser
#

yes

#
    let email = '';
    let password = '';

    let errors = writable<{ email: string; password: string }>({ email: '', password: '' });

    function onSubmit() {}
#

and then I bind my inputs bind:value={email} bind:value={password}

#

and then I do on:submit={onSubmit}

#

I really dk what im doing

#

😔

frosty gale
#

use SubmitEvent as type

#

youre welcome

#

although the event itself doesnt give you too much info

sharp geyser
#

how does bind:value work

#

does it set the value once they click out of it

#

or is it as they are typing?

#

because if I can just bind the value to a variable

frosty gale
#

yes it attaches the value of the input to the variable

sharp geyser
#

I can just not listen to any event specific parameters

frosty gale
#

so if you change the value of the variable in js it will change the input too

#

and if the user changes it too

sharp geyser
#

and just post using email password variables

frosty gale
#

true web devers bind the form inputs to variables so you have quick reactive access to them

#

although if you dont need them to be reactive you dont have to

#

you can just get the values when the form submits

sharp geyser
#

ok

#

how do I do that

frosty gale
#
const formData = new FormData(e.target);
const formProps = Object.fromEntries(formData);

formProps gives you an object of all of the values in the form

#

make sure to do |preventdefault too otherwise it will submit the form

sharp geyser
#

isnt that what I want tho?

frosty gale
#

idk youre doing a custom onsubmit event so i figured that you werent

#

otherwise if you want the form to automatically subimt the data to the server you wouldnt

sharp geyser
#

how do they submit the form otherwise?

frosty gale
#
<form method="post" enctype="application/x-www-form-urlencoded">
#

although be warned the data that is sent isnt json

#

its form urlencoded

#

you can parse that on the server too though with middleware

#

if you want json you have to go the custom route

sharp geyser
#

ah my backend handles form submissions

#

:D

#

It has an extractor for x-www-form-urlencoded type data

sharp geyser
#

if you dont have an action going with it

#

I also have no need I think as I will be submitting the values manually via onSubmit

#

my question was if preventDefault prevents the form from fully submitting

#

then wont that cause issues?

frosty gale
#

which will probably mess up your page

sharp geyser
#

ic

#

I understand that

#

My question is, what do I do when its time to submit the form, or is there no need to let it do its thing and simply just redirect them when login is done

frosty gale
#

if you want to send the data to the server manually you dont need the form to submit itself anymore since youre handling that yourself

#

you will still get the submit event though which will let you know that the user clicked "login" or whatever

#

in your js youd get the form data and send it to the server somehow

#

then redirect the user ig

sharp geyser
#

Ah ic

#

I thought it prevented the submitting

#

meaning i'd get nothing

frosty gale
#

hence the name preventDefault

sharp geyser
#

I can't get FormData from the target

frosty gale
#

why not

sharp geyser
#

because its empty

#

new FormData(event.target as HTMLFormElement) is empty

frosty gale
#

lies

#

your form must not be done properly

#

all of your inputs are inside the form and have names?

sharp geyser
#

unless you see something im not

#

yes

#
    function onSubmit(event: SubmitEvent) {
        const formData = new FormData(event.target as HTMLFormElement);
        console.log(formData);
        const formProps = Object.entries(formData);

        console.log(formProps);
    }
quartz kindle
#

or console.log([...formData])

#

formData is a very weird class, all its properties are hidden, the object itself is always empty

#

the only way to access the data is by using its built in iterator

sharp geyser
#

oh thanks

#

that worked

sharp geyser
#

separated by ,

quartz kindle
#

ye

sharp geyser
#

Error: Function called outside component initialization

#

bro wtf is this

#

😭

#

telling me to use onMount

#

but how tf am I going to do that when the function takes in params

glacial haven
#

He

sharp geyser
#

On login, should I store it in localstorage (so it persists on restarts) or in a store or both?

#

and if both, how do I repopualte the store on say restarts

#

and if only in localstorage, how do I handle retreiving the data efficiently because fetching from localstorage each time someone refreshes the page seems inefficient

quartz kindle
#

i mean

#

from the looks of it

#

youre using svelte as a fullstack framework

#

so you're using SSR

sharp geyser
#

I actually stopped using superforms which requires a .server.ts file

#

and do the validation in the page.svelte file

quartz kindle
#

lets see if i can explain correctly

#

like

#

you have two ways of working, generally

#
  1. SSR (server side rendering):
    browser requests page
    server receives request
    server processes sessions and states
    server renders/generates page (components are processed, stores are loaded and populated, data resolved and is inserted into the page)
    server emits/sends raw pre-built html+css+js to browser (which already includes the data inside the html)
    browser displays page

  2. CSR (client side rendering):
    browser requests page
    server receives request
    server sends raw html+css+js files
    browser begins loading page
    browser runs functions (fetch, localstorage) and updates page accordingly
    browser displays page

sharp geyser
#

why did I think frontend would be a cool hip thing to try

#

I am regretting my decision

quartz kindle
#

with SSR you dont really need localstorage nor fetch

#

its like php

#

on every page request, your server runs serverside things and injects data into the html

#

with CSR you have to fetch stuff and store in localstorage otherwise you lose data when you navigate to a different page

sharp geyser
#

😔

#

I dont know what to do tim

#

im a backend developer

#

this is out my depth

quartz kindle
#

stay with SSR then, its the sveltekit default mode

#

so you dont need localstorage

sharp geyser
#

ok

#

cool

#

now what

#

😭

quartz kindle
#

on login you generate session cookie, on every page load your serverside js files check for session and add data to components

sharp geyser
#

Im confused....

quartz kindle
#

so essentially, you use svelte stores to hold user data only if a session exists

sharp geyser
#

I already have a login endpoint that returns user data

#

and I have an endpoint that can be fetched if need be to get that user data based on the session

sharp geyser
#

Here's the thing

#

I've been trying for what, 8 hours now

#

and I can't get stores to work

#

It just wont set the user data in the store

#

I have no fucking clue what im doing wrong

#

Also for SSR to be a thing, don't I need to use +page.server.ts files?

quartz kindle
#

i have never done this myself before, but im pretty sure what you need is contexts

#

(scroll down to context)

sharp geyser
#

Im using context

quartz kindle
#

you're missing the cookie handling

sharp geyser
#

wdym

quartz kindle
#

example

sharp geyser
#

uhm

#

why do I need to touch cookies

quartz kindle
#

because thats how you check if a user is logged in or not

sharp geyser
#

my login endpoint sets a cookie for the session and returns the user data based on that session?

#

I am confused

#

why does my frontend need to get something that is already set

quartz kindle
#

any page in your website, ie /home, needs to check if a session exists or not

sharp geyser
#

right

#

but

#

isn't that the entire point of stores

#

its going to be empty if they aren't logged in

#

so why do I need to check for a cookie

quartz kindle
#

because thats where the session is stored

sharp geyser
#

but all the cookie gives me is some random id assigned by the backend

#

its usless on its own unless you are requesting protected routes

quartz kindle
#

thats why you have a database of session ids

#

linking session to user

sharp geyser
#

correct

#

im not sure I follow your thought process

#

The backend does all the checks

#

If the frontend is fetching a protected route ON the backend, and they aren't logged in, it responds as such

quartz kindle
#

user visits page (not logged in)
page checks for cookie (does not exist)
page renders non-logged in
user logs in via form
form posts login data
server saves session cookie
user is redirected
user visits page (logged in)
page checks for cookie (does exist)
page renders login-only stuff

sharp geyser
#

ok

#

but

#

question

#

Is the entire point of stores usless then?

#

If a store is empty that EQUALS them not being logged in

quartz kindle
#

stores and contexts are for handling data between svelte components
when a user visits a page, svelte generates the page by running the components and building the page
the components create stores and contexts for other components and child components to know whats going on and render accordingly
once the page is done and sent to the browser, everything is gone
when the user visits another page, the entire component process is started again, stores and contexts are created so that child components know whats going on, etc

#

of course svelte caches a big part of this process

#

so that when a user visits a different page, most of the component stuff is already pre-rendered

sharp geyser
#

Ok

quartz kindle
#

svelte store is not a real persistent storage, its created and destroyed on every page visit

sharp geyser
#

so my question to you is

#

Why do people make websites

#

This shit is so annoying

quartz kindle
#

because they hate themselves

sharp geyser
#

Im starting to realize that

quartz kindle
#

check out alpine.js

sharp geyser
#

On a serious note

#

wtf is this

sharp geyser
#
  1. User logs in
  2. Server sets a cookie
  3. User redirected to home page
  4. Main layout checks cookies to see if they are logged in
  5. If so, grab the user data from an endpoint and return it to the client
  6. Inside the layout, grab that data, set it in a store and then in context
#

The only reason I say check cookies in the main layout, is because if they are logged in, the navbar will reflect that, so it seems like the most obviously place to check this and set if they are or aren't

#

I might be misunderstanding your explanation though

#

Because im not exactly 100% sure on where I should check if they are logged in or not, without doing so on EVERY single page that requests data from a protected backend endpoint

#

which idk about you seems inefficient

#

Although I will note, if someone requests data from a protected endpoint and they aren't logged in, my middleware on the backend automatically redirects them to the login page

#

so if they try and access say
example.com/dashboard and dashboard frontend route requests data from the backend, and is a protected route. if they aren't logged in, my backend will be like "Hey go here instead"

quartz kindle
#

step 6 happens inside the server still

sharp geyser
#

what

#

but the svelte devs themselves said NEVER set data in stores inside the server side

#

Lest you want bill to see sally's data

quartz kindle
#

lol wut

sharp geyser
#

🦐

#

Idk

#

its what they said

quartz kindle
#

checking the cookie and setting up the store with the user data happens on the server side

sharp geyser
quartz kindle
#

then the components are rendered and the layout drawn based on that data

sharp geyser
#

This is why I dont fucking ask for help in framework specific servers

#

they lied to me

#

I showed them how i was doing it before, which was setting the user data on the server side

#

and they were like "no no no, you are sharing that with everyone"

#

😔

quartz kindle
#

i mean

#

the docs do say to use contexts not the store directly

sharp geyser
#

😔

#

Right

#

but im still confused on the cookie thing

#

or wait

#

Since I am redirecting them back to the home page I can check the cookie in
+layout.server.ts which will be able to see if the cookie exists aka if they truly did login, or just visited

#

if they do have a cookie, set user data

#

if not, cool go about your day but you can't visit any protected pages

#

My only question is, I obv don't want to send useless requests to the server if I know they aren't logged in, so how do I render the page as being 403 (Unauthorized) without fetching server backend first to check

quartz kindle
#

so you can ismply check for the cookie, and if it doesnt exist, directly render an html component with a big 403 text

sharp geyser
#

I see

#

I think I might need to use hooks for this

#

time to do more research

pearl trail
sharp geyser
#

Right I fucking give up

#

I cannot for the life of me, get these fucking stores to work properly

pearl trail
#

about cookies thingy?

sharp geyser
#

No

#

not even that

#

I have all that

#

It wont set the fucking data in the store

#

its like I ask it to, but then its like "nope, I dont wanna"

pearl trail
#

time to use window.localStorage.setItem("", "") Troll

scenic kelp
#

where are you setting the stores

#

it can be a bit unintuitive at first because of how sveltekit kinda blurs client and server

pearl trail
#

oh sveltekit is just like nextjs?

sharp geyser
#

in a ts file that has a function called validateUser (which fetches an endpoint for user information while checking they have a cookie) and then calling this function inside hooks.server.ts

#
import type { Cookies } from "@sveltejs/kit";
import { userStore, type User } from "./user";

export async function validateUser(cookies: Cookies): Promise<User | null> {
    let session_id = cookies.get('id');

    if (!session_id) return null;

    let response = await fetch('api/users/@me');

    console.log(response)

    let userData = await response.json();

    userStore.set(userData)

    return userData;
}
#
import { validateUser } from "$lib";
import { redirect, type Handle } from "@sveltejs/kit";

export const handle: Handle = async ({ event, resolve }) => {

    event.locals.user = await validateUser(event.cookies);

    if (event.url.pathname.startsWith('/app')) {
        const fromUrl = event.url.pathname + event.url.search;
        console.log('Hello')
        if (!event.locals.user) {
            throw redirect(303, `/login?redirectTo=${fromUrl}`)
        }
    }

    // Stage 1
    const response = resolve(event)

    return response
}
#

im also setting the userdata in event.locals so I can use it in server-side components without fetching from store

sharp geyser
#

also i notice I can't do /api/users@/me

#

apparently its not recognizable despite the api running on the same domain proxied with nginx

#

hm, wait it seems I can't use stores on the server

#

so wtf am I supposed to do

scenic kelp
#

since they're actually stored on the server

#

are you just trying to pass data between the client and the server?

sharp geyser
#

What im trying to do is store the user data when they login so I can use it to display on the client side, or even make future requests for more detailed data

scenic kelp
#

imma keep it real i have like a very similar issue and i just gave up and moved on cause i'm too lazy to figure out an elegant way to pass data

#

like obviously there is i'm just missing something

sharp geyser
#

😔

#

Im doomed

scenic kelp
#

it's so over sveltebros

sharp geyser
#

Im

#

like

#

so annoyed

#

because frontend is the only thing stopping me rn

#

I can code the backend in a giffy if I really wanted to, for the past 3 days i've been trying to figure out how to log people in and display the data

sharp geyser
#

@scenic kelp right so the responses from the svelte devs

#

use hooks to set event.locals.whatever then inside your page.server.ts file load functions returns something like

export const load = ({ locals }) => {
  return {
    whatever: locals.whatever
  }
}

and in your component use $page.data

#

apparently thats how you are supposed to do it

scenic kelp
#

oh right

sharp geyser
#

but its not reactive

#

so idfk what you are supposed to do if they say change their name

scenic kelp
#

you can use a store on the client side though

sharp geyser
#

How would that work?

#

do you just rely on $page.data.whatever not being null or smth

#

ig you can make it nullable

#

and just allow your store to also be nullable

scenic kelp
#

yeah something like that

#

it's 2:30

#

i'm not gonna be of much use lol

sharp geyser
#

ye nah all good

#

I'e been working on this for the past 2-3 days

pearl trail
#

can i pass something to discordSecretMiddleware ?

func discordSecretMiddleware(next http.Handler) http.Handler {
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
          // my code
    })
}

func smth(router bla, db bla, rest bla) {
  router.Use(discordSecretMiddleware)
}

i want to pass the db and rest to discordSecretMiddleware

sharp geyser
#

what are you using

#

is this go

#

no way right

pearl trail
#

yes go

#

go go power ranger

sharp geyser
#

what are you using

#

mux?

pearl trail
#

yep

sharp geyser
#

so

#

you can quite literally

#
func something(yourParams) http.Handler {
  return func discordSecretMiddleware(next http.Handler) http.Handler {
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
          // my code
    })
  }
}
#

and just use something as the middleware

#

:)

pearl trail
#

o fair

#

lemme try

sharp geyser
#

its a deeper callstack

#

so careful

#

idk how go handles function callstack

#

esspecially since HandlerFunc takes in a func

#

💀

pearl trail
#

it's fine ig

#

need some tweaking

func createDiscordSecretMiddleware(cassandraService *services.CassandraService, service *services.RestService) func(http.Handler) http.Handler {
    return func(next http.Handler) http.Handler {
        return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
                  // my codes
        })
    }
}
#

thanks!

sharp geyser
#

No problem

pearl trail
#

thank for searching that for me Nene_Happy

sharp geyser
#

np

#

I figured that would be the solution but i had t ofact check myself

past field
#

can bots have an animated profile pic?

tight veldt
#

and banner if you want

past field
past field
#

dang it

#

that sucks

faint crystal
#

is there any bot devs that can make me a custom bot?

past field
faint crystal
#

idk if its classed as simple cus ive never made a bot before

past field
deft wolf
faint crystal
past field
faint crystal
deft wolf
#

Then it's a good time to learn. The problem with creating bots on Discord is not writing it, but firstly hosting it + maintaining it because, for example, discord.js likes to make changes to its library quite often

past field
# faint crystal i cant make one lol idk anything abt coding

you can if you dedicated yourself to learn! i just started not too long ago. @deft wolf will tell you. i came here not knowing the first thing about coding, dedicated myself to learn and although i still have lots to learn, this community has really helped me a lot.

deft wolf
#

If your bot stopped working, you would have to look for someone to fix it for you again

past field
#

now i have my own fully custom bot and i created a game bot that’s in several servers and still getting requests to add it to their server!

stable hinge
#

ali cabbar is bot owner

faint crystal
deft wolf
#

Learning would save you money because you will either have to hire a developer for a longer period of time or pay every time you need a developer to fix some error in the bot + add something to it

past field
faint crystal
wheat mesa
#

There’s a ton to learn but you can start very quickly

solemn latch
frosty gale
#

my guy is not interested in code

#

he just wants a bot lol

solemn latch
#

^

frosty gale
#

thats understandable

solemn latch
#

If thats all it needs, does it need to be unique to a server?

faint crystal
#

so its not easy to type all that lmao

solemn latch
#

If it doesn't need to be unique to the server, you can just use userIDs.

Discord already assigns a unique "code" to each user across all servers.

#

-ui 136583532972605440

gilded plankBOT
#
» Username

woo#0

» ID

136583532972605440

» Nickname

None

» Highest Role

Moderators

» Badges

​None

» Joined Server

<t:1591373246:F> <t:1591373246:R>

» Creation Date

<t:1452634452:F> <t:1452634452:R>

solemn latch
#

136583532972605440 would be mine

#

I could not be in the server and that ID would still be searchable through discord.

frosty gale
#

topgg should make a place for people to post advertisements for devs since im sure there are a lot here that would be interested

solemn latch
#

I feel like people ask for help here a few times a week looking for a dev.
Anyone could send this person a DM and make an offer

#

(If someone does make an offer, make sure they understand they will be paying server fees)

frosty gale
#

then again a lot of people asking here for devs dont have the budget for it and dont know how much developers tend to charge

#

come with a $20 budget

#

some devs would be happy to do that but it becomes a bit messy

#

but you shouldnt expect a quality bot

solemn latch
#

Yeah.

deft wolf
#
  • Make me a bot like Dyno
  • How much are you willing to pay?
  • You will get a role on my Discord server
solemn latch
#

Even my fee would probably start at $100 if they dont want to use discords userIDs.
Just for the extremely simple feature set that's been mentioned.

#

Assuming I'd have to rent the server, setup the server.

#

Then the monthly server costs

earnest phoenix
#

Looking for a dev for one page frontend for a restaurant's menu

gilded plankBOT
#

You seem to be asking for something you don't have experience for or something that hasn't been done yet, but really need for your bot/server.
You can hire developers from Fiverr or Freelancer to code the things you need for your bot/server.

solemn latch
#

(or for websites)

frosty gale
quartz kindle
#

what looks better

#

or this

lyric mountain
#

first, spaced params makes it odd to read

#

also %20 please mmLol

quartz kindle
#

lmao

#

isnt it harder to read if its all clumped together?

lyric mountain
#

or +, like google

#

idk, imo it's easier but u could use a different color for &

quartz kindle
#

how to do that in markdown

lyric mountain
#

span

quartz kindle
#

thats not markdown :^)

#

but ye i guess

lyric mountain
#

markdown allows html too

quartz kindle
#

what about this

#

making parameter keys stand out compared to values

lyric mountain
#

you can use a table for explaining params

#

param | args | description

quartz kindle
#

i dont wanna use tables on this case

#

im making this for dummies, some people cant read tables and translatre that to a string parameter

#

:^)

lyric mountain
#

well, it's fine then, tho the underline is a bit out of place

quartz kindle
#

better like this then?

lyric mountain
#

feels cleaner yeah

#

u can use span to color the params if u want to make it clear that it's separate from the description

#

but that's separate enough tbh

quartz kindle
#

ye ill just leave it like that then

#

see this is how i waste my time, doing bulshit microdesigning that nobody cares about instead of actualyl coding

#

:^)

#

noooooo

#

what am i gonna do now

#

#broke

solemn latch
#

No recovery from this

quartz kindle
#

i will never financially recover from this

#

:^)

surreal sage
#

im thinking about creating a download page for my tauri app

any tips on how i could approach this?

(release assets look like this)

#

what about fetching all assets and like

macos.arm = github.com...aarch64.dmg
macos.x64 = github.com...x64.dmg

quartz kindle
#

and have the download page show the link for their OS

surreal sage
#

but no error during build

lyric mountain
stable hinge
#

@rustic scarab

surreal sage
lyric mountain
#

well you buildscript is shitting itself

#

or perhaps a parser issue, did you try smth else to edit that file?

surreal sage
#

schizophrenic

#

huh

lyric mountain
#

the editor

#

try some other tool to see if it's a parser issue

surreal sage
#

oh my fucking god

#

i was like

#

why tf

#

is coolify not working

#

but no shit

surreal sage
past field
#

how can i address race condition issues?

quartz kindle
#

as there are many ways to solve it

past field
# quartz kindle depends on the condition

in my click war game, some players keep saying they are getting “interaction failed” and are being eliminated for not getting their response collected, i don’t get any errors and i even added logging to see how many are actually being collected. idk if these people are lying or not but the only thing i can think that would cause that is maybe they are tapping the same button at the exact same time? idk im stuck

past field
quartz kindle
#

can you send the code again?

past field
#

yes give me about 15 mins

lyric mountain
#

ah, I think I kinda understand what it is supposed to be

#

they have to click asap right? it's possible you're being ratelimited

#

by your description it can't be a race condition, js is single-threaded and user network delay would be big enough to allow plenty of space between clicks

#

I'd advise against any reaction-based games, as it'll be very biased towards users with better connection, and your own bot's latency could heavily affect the outcome of the game

green kestrel
rustic scarab
stable hinge
#

@rustic scarab

past field
quartz kindle
#

rate limits do not apply for interaction responses afaik

#

each person sees their own button, which generates its own token

past field
#

hm. so i guess it just boils down to either my internet connection or the players internet connection?

#

or discord API lags a bit with that many players?

#

what are your thoughts? @quartz kindle

quartz kindle
past field
#

they are reporting “interaction failed”

quartz kindle
#

and you dont see any error on your end right?

past field
#

correct

quartz kindle
#

for those users that failed, do you see their id in your logs?
this one specifically

console.log(`Collected interaction: ${i.customId} from ${i.user.id}`);
past field
#

i’d have to try and get another big game going and have players screenshot their interaction failed and look

quartz kindle
#

alright

surreal sage
#

time to use an eslint plugin that hasnt been updated since

quartz kindle
#

in any case, there is a chance its discord's fault, or the user having an outdated discord app

#

but strictly from your code's perspective, there are some things that can be improved in regards to timings

quartz kindle
#

but i dont see any major point of failure

quartz kindle
#

the main issue with your code is that you have two timings happening at the same time, the game round time and the interaction collection time

#

and those timings are independent from each other, which they shouldnt be

#

this by itself does not cause a direct issue, but can cause weird behavior in case of blocking and major lags

#

so my suggestion is

#
  1. get rid of the while loop and make the function recursive (or make a separate function)
  2. on collector end, wait 2 seconds, then call the game function again
#

for example:
rungame() -> create collector -> handle interactions -> on collector end -> wait some delay -> rungame() again

#

this way you have more control of the timing, and if some major lag happens, there is no chance of the next round being run too soon

#

other than that, take note of the ids of people who have that problem, and see if you receive events from them at all or not

#

might be an issue with their app, or discord itself

lyric mountain
#

ah nvm

quartz kindle
#

there are a lot of other things i would personally do differently, but it wouldn't change much for the end result

#

there is a lot in that code that can be simplified, the whole thing can be much smaller / fewer lines of code

sharp geyser
#

might sa well change your nick to that

#

JS Optimizer

deft wolf
#

opTIMizing

quartz kindle
#

lmao

sharp geyser
#

oh tim

#

I got the login thing to work

#

:D

#

it uses the built in page store

#

and because of that, every page will have access to it

#

:p

stable hinge
#

@shell tundra

frosty gale
surreal sage
#

weekly prune!

lyric mountain
#

The hell did you prune?

#

A whole tree?

pearl trail
#

probably their unneeded homework files

sharp geyser
#

nah

#

that'd be like 1tb

pearl trail
#

damn

lament rock
#

npm cache for one project is a more reasonable assumption

sharp geyser
#

reasonable?

#

That shouldn't be reasonable

#

30gb for an npm cache is absurd

pearl trail
#

nah

#

it's normal

sharp geyser
#

thats the thing

#

it shouldnt be

#

its absurd

quartz kindle
#

someone is being trolled

#

:^)

sharp geyser
#

no way I am

#

because node_modules on its own can reach absurd sizes

quartz kindle
#

only if you use react

sharp geyser
#

no

#

if you use any modules

quartz kindle
#

#shotsfired

pearl trail
quartz kindle
sharp geyser
#

161mb is too big

quartz kindle
pearl trail
sharp geyser
#

I prefer my 4gb target folder for my rust projects

#

:)

quartz kindle
#

a big chunk of node_modules is dev deps

#

eslint, ts, etc

#

those are stupid large and serve zero purpose on runtime

sharp geyser
#

lets see ewhat the current size of my target folder is :)

quartz kindle
#

always omit dev in production

sharp geyser
#

4.6G

#

for the entire folder

#

729M for release builds

pearl trail
#

rusty

sharp geyser
#

3,9G for debug builds

#

a release binary is also like 8x less

#

14x*

#

debug has 0 optimizations and just builds your code as is though, so release throws out what it doesn't need and keep what it does

eternal osprey
#

Miauw miauw

spark flint
#

i love linux

#

literally haven't tpuched this VM for like 3 months

#

can't ssh in

#

client_loop: send disconnect: Broken pipe

pearl trail
#

holy 💀

sharp geyser
sharp geyser
#

@scenic kelp im bout to explode bro

#

I swear

#

I have no idea if its my css, or svelte itself, but the video player I am trying to make is not showing up ghostie_angry

#

Just tried the same setup on react and it shows up fine

scenic kelp
#

code issue

sharp geyser
#

well idk

#

the media player is originally for react

#

it might be a bug in the svelte port

pearl trail
#

create your own Troll

#

shouldn't be that hard

radiant kraken
pearl trail
radiant kraken
#

yeah cuz you're pro

#

fr fr

surreal sage
#

the struggles of trying to make next/image work

pearl trail
#

what's the difference between next/image and normal <image/>

surreal sage
#

optimization

pearl trail
#

ooo

surreal sage
#

if u have a 1920x1080 image but it shows on the site as e.g. 480x270, it'll resize to ~480x270 on the server

pearl trail
#

whoa

#

i see isee

#

luckily nextui automatically use next/image

neon flicker
#

Is guild.me a still valid property?

sharp geyser
#

depends on that library you are using

solemn latch
neon flicker
#

Thank you, is it possible to provide an array into permissions.has()?

#

Instead of using lots of .has() functions

deft wolf
solemn latch
#

I think you need to use bit flags right?

#

oh cool, easy ^-^

neon flicker
#

Thank you

sharp geyser
#

woo

#

please

solemn latch
#

Whats up?

sharp geyser
#

I need to know how to load user data from an endpoint on initial load (e.g when they visit the site for the first time) and also protect my pages

#

My backend api written in rust handles creating the session and setting the cookie

#

My frontend just needs to

  1. Login & Redirect back to home page
  2. Display the data fetched from /users/@me (which also gets stored in state using zustand (which just uses context and state) )
#

which was placed in a +layout.server.ts which the load function gets ran only once

solemn latch
#

So you already have the login? you just need the state part?

sharp geyser
#

yes

#

my login endpoint returns no data because it makes no sense to save state then and there

#

as if they leave the page it goes away

#

I need to be able to load state when they visit the website

surreal sage
#

is this a fair way of doing this or is there a better method

#

guess there is using regex but it's not much of a difference as the regex has to be hardcoded as well, nvm!

solemn latch
sharp geyser
#

I mean i'd like not to spam my api for requests of data that I already have

solemn latch
#

Store it in localstorage?

#

I use nextauth, which just spams session requests, lmao

sharp geyser
solemn latch
#

Assuming its just username and avatar and basic non private information I'd just chuck it in localstorage.

sharp geyser
#

hm

solemn latch
#

If its a secured page you'll want to fetch the session information every page load though.

sharp geyser
#

I wish the media player I was using worked with svelte

#

this is more annoying than anything

solemn latch
#

If your backend is reasonably fast you should be able to handle thousands of /user/me requests a second even on extremely basic hardware.

#

It feels like this is pre-optimizing for something you wont need to worry about for years.

sharp geyser
#

this isn't for some bot though

#

this is for a site that is meant to be heavily trafficed

#

So thousands could turn into hundreds of thousands a second

solemn latch
#

I mean, top.gg sends session data all the time.

#

maybe it doesnt anymore 👀

#

It still sends every page visit

sharp geyser
#

I mean ok

pearl trail
#

just use fast db™️

solemn latch
#

well, assuming the login/logout system is all in one place session data can reasonably be cached in the backend. As long as that cache is properly invalidated whenever someone updates their profile or logs out.

#

But thats mico-optimizing.

#

I wouldnt worry about that until later.

quartz kindle
#

i have been trying to get http3 work on my nginx since like last year, spent tons of hours trying every single config and it never worked

#

today i found out why

#

port 443 UDP was blocked on the hetzner firewall

#

@_@

surreal sage
quartz kindle
#

for some reason it still fails the domsignal test, but it passes http3check test and shows up as h3 on network tab from second load onwards

frosty gale
#

galaxygate has literally no firewall as far as i know

#

you have to set one up yourself with ufw

#

thats a deathtrap for people new to managing servers

#

very easy to accidentally expose internal ports

neon leaf
#

I mean skill issue for binding internal things to public interfaces

frosty gale
#

@quartz kindle why are b trees more commonly used for database indexing

#

at least i think they are

#

b+ trees are way better suited for databases

#

since you can easily do range queries

#

just need to traverse down the tree between 2 ranges and select all the leaf nodes in between

quartz kindle
#

im pretty sure most dbs support both

#

and lets you chose

eternal osprey
frosty gale
#

yeah probably

#

the internal nodes dont store any data so they essentially just take up space

#

as opposed to b trees where they also store data

#

and it doesnt matter if you find the key in the internal node you still have to traverse down to the leaf node

#

for simpler database structures and query types b trees seem to have more benefits

#

for more complex queries like ranges you should use b+ trees

#

as with everything in life theres a trade off between the two

sharp geyser
#

I had to leave svelte behind Chloe

frosty gale
#

svelte doesnt miss non believers

sharp geyser
#

😔

#

It’s not my fault

#

The media library I was using was not working on svelte

frosty gale
#

thats like switching your entire programming language mid development because a library doesnt work

sharp geyser
#

uhm

#

yea if you can't continue the project without it

#

💀

#

I quite literally needed that library to continue my development

#

There was no other alternative

digital swan
#

Make your own duh

sharp geyser
#

uhm sureeee

#

Ima make my own media player from scratch that supports hls streaming, accessiblity, state management (to keep track of where they were, and are) and many other things a media player needs to do by myself

#

because thats more reasonable

digital swan
#

Yeah obviously

#

Just whip it up over the weekend

sharp geyser
#

Yes you are so right

#

Also

#

I just found out reacts way to do it

#

I have to load the data server side, pass it along to the client side via a component, and then store it in context

#

💀

digital swan
#

React just seems infinitely more complex than svelte

sharp geyser
#

I mean its not really much different from svelte, except I could load it in the server and return it, and have access to it immediately via page store

sharp geyser
#

until then

#

im stuck with react as vidstack was made for react first and 100% works

digital swan
#

Their website says it works seamlessly with svelte

sharp geyser
#

supposedly yes

#

but I can't even get it to load via vite which sveltekit uses

digital swan
#

I assume you followed their get started thing too

sharp geyser
#

yea

frosty gale
#

its not too bad anyways

#

quite a fun project

sharp geyser
#

idek how

#

or where to begin

frosty gale
#

this is where your video will play since it is hardware accelerated by the browser

#

you can then hide the default controls and panels and make your own with html+css

sharp geyser
#

will this embed directly into the page?

frosty gale
#

you can then control pausing, resuming, loading chunks of the video player using javascript

sharp geyser
#

or will it appear "popped out"

sharp geyser
frosty gale
#

its any other element

sharp geyser
#

There's a lot I have to read up on it seems

frosty gale
#

the video player will generally handle buffering

#

you just need to focus on getting the chunks to the video player

sharp geyser
#

I thought buffering was something I had to do

frosty gale
#

the browser makes it very easy

sharp geyser
#

Which was why I was going to use an already made video player

frosty gale
#

you can either stream the entire file over and the video element will detect that

#

or you can send the video with chunks which is much faster and efficient and the element will detect that

#

no javascript code needed only server side

#

it will also ask for the relevant chunks if you decide to seek manually in the player

#

very simple

#

the only frontend code thats needed to do buffering and chunking

sharp geyser
#

well you see

#

I use hls

#

not actual mp4/mp3 files

frosty gale
#

not a problem

#

you just do the streaming from the server differently

#

in the request for chunks the browser will ask you for the next chunks and its position

#

and you can provide those depending on what you do

#

if the video element doesnt support your format you can probably convert it to mp4 or something else on the fly

sharp geyser
#
#

Which makes it easier to stream hls playlists in the browser

sharp geyser
#

Had I know it'd be this easy to get started I would of done it earlier

#

My biggest concern will be keeping track of where they are in the video in case they come back to it later but I can implement those finer details as I go and work on the project

queen needle
#

That shouldn't be too bad though, especially if you are okay with being like 1-2 seconds off

sharp geyser
#

Yea

#

baby steps tho

#

:p

queen needle
#

Just an implementation of auto save basically

solemn latch
#

I did this awhile back.

https://i.woo.pics/41ad639808.mp4

It would get the current frame of the video, and figure out what part of the game they were in. Then map that frame to whatever relevant data is going on in the game.

#

That was a fun project

queen needle
#

There's probably a better way, like using websockets and detecting disconnecting and then making it save on disconnect or something

queen needle
solemn latch
#

For a joke project I spent way too much time on it.

queen needle
#

Might be useful for a layer project though

solemn latch
#

I'm too expensive! 😉

sharp geyser
#

I bet

#

my budget is 0$

#

take it or leave it

solemn latch
#

shoot, im $3

sharp geyser
#

Fuck I need to make 3$

#

well

#

now that I have the motivation to make my own media player

#

svelte is back on the table (thank god)

#

state in react is so fucking annoying

queen needle
sharp geyser
#

It defeats the entire purpose of state

queen needle
solemn latch
#

But yeah, I could see that

sharp geyser
#

I will likely store placemnet in a video in my db

#

so that way they can watch multiple videos and if they decide to leave in the middle of em they can pick up where they left off

queen needle
#

Like YouTube but then you could map the data custom for things like that^ being easy

sharp geyser
#

just like some "Store x time they were at in a table"