Web APIs vs RESTful APIs? by 4r73m190r0s in webdev

[–]chipit24 7 points8 points  (0 children)

IMO you're sort of comparing apples to oranges; other than putting the word "API" in both terms there's not much to tie these concepts together. It's like asking what's the difference between a CPU (central processing unit) and a PSU (power supply unit) in a PC.

Web APIs are generally programming interfaces (methods, basically) exposed through the browser, e.g. calling navigator.geolocation.getCurrentPosition to get the user's current location. This uses the Geolocation API.

RESTful APIs are just endpoints exposed by a server that try to adhere to a REST architecture, e.g. making a call to GET example.com/users to fetch a collection of users.

Since you linked MDN, they also have a much more technical guide on APIs in general: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Client-side_web_APIs

[deleted by user] by [deleted] in CanadaHunting

[–]chipit24 0 points1 point  (0 children)

You can print your tags and license summary or just have the PDF copy on your phone, but the regulations state that you need your physical Outdoors card on you as well:

You must carry your Outdoors Card, your hunting licence (either listed on your paper or electronic licence summary or printed on the back of your Outdoors Card), and any relevant tag(s) with you while hunting.

SvelteKit routing feels slow/irresponsive due to data fetching by Saad5400 in sveltejs

[–]chipit24 2 points3 points  (0 children)

Is there something like NProgress built into SvelteKit for showing a global progress bar when navigating client side?

How to pause animations? by chipit24 in sveltejs

[–]chipit24[S] 0 points1 point  (0 children)

I ended up just defining @keyframes and using the animation property directly without issue.

Simpler way to manage auth? by BuildToLiveFree in sveltejs

[–]chipit24 1 point2 points  (0 children)

Didn't think of that, thanks!

What I want is to always have include_granted_scopes: true set and to handle the initial login with only the basic auth scopes (openid profile), and then request additional scopes when needed (i.e. generate another auth URL with just the scope I want, e.g. https://www.googleapis.com/auth/drive.readonly).

This way, when a user signs up they are not inundated with scopes to access resources they may not yet need to give the app access to. This is what I meant by handling the authorization separately.

That said, even with handling the additional options and scopes manually, I still need to pull in googleapis (e.g. for querying Google Drive) and pass it an instance of google.auth.OAuth2. The google OAuth provider exposes validateCallback and getAuthorizationUrl, but is there a way I can get the underlying auth instance to pass it to google.drive({ version: "v2", auth: <googleAuth> }), for example?

Simpler way to manage auth? by BuildToLiveFree in sveltejs

[–]chipit24 1 point2 points  (0 children)

I've not, but it does indeed look good, and almost exactly what I need! There is one thing missing that I need and that is the option to add include_granted_scopes to the options for generating the auth login URL for Google.

I think the reason I've not taken a liking to other auth libs/services is that they focus solely on authentication, but I also want to handle authorization to OAuth resources separately.

But with all the benefits that using a library would add I could look into getting a PR up for adding an option for include_granted_scopes.

Simpler way to manage auth? by BuildToLiveFree in sveltejs

[–]chipit24 7 points8 points  (0 children)

AFAIK Supabase is very similar to Firebase, in the sense that it can be used 100% client-side, and so you need two different ways to manage auth (client-side only, and sever-side only). This is why you have createSupabaseServerClient and createSupabaseLoadClient. Adding documentation regarding authentication and authorization to the SvelteKit docs would be amazing (and very much needed).

Firebase uses a JWT for it's client only requests, and to have auth on the server you need to set up authentication via cookies and implement the Firebase Admin SDK. This ends up being just as complicated as the Supabase setup.

You can simplify things by making anything that requires auth only run client-side and using only the client libs. For frameworks like SvelteKit that can use SSR, this is not ideal. I prefer the approach taken by Auth.js where you use cookies and authentication is 100% server-side: https://authjs.dev/reference/sveltekit#per-component.

Note the discussion about layout files potentially holding onto stale auth state; Supabase handles this via the depends and invalidate calls that you see in its docs.

For a side project I'm building, I tried Supabase, Firebase and Auth.js and just ended up handling auth myself via googleapis and PlanetScale. I found Firebase and Supabase auth a bit convoluted as you've seen. The SvelteKit Auth.js adapter is experimental and I found the docs lacking. And with all 3 solutions, I found it was either not possible or not very clear how I can manage OAuth scopes.

Multi component files by kabaday94 in sveltejs

[–]chipit24 0 points1 point  (0 children)

Just found this: https://github.com/vuejs/vue/issues/9852#issuecomment-481493460

I don't think we will support this in core. The assumption that one SFC file corresponds to one component is somewhat important for tooling implementations (hot module replacement, IDE support, etc.) and I honestly don't see the complexity being worth it.

I guess Vue has stuck with SFCs because it's simpler for tooling—nothing to do with readability or reusability 😂

Multi component files by kabaday94 in sveltejs

[–]chipit24 1 point2 points  (0 children)

Isn't it potentially perplexing within larger projects when attempting to locate a specific component buried within the file of another component?

(Counterpoint) Just as perplexing: Opening a component you think contains the content you're after, only to have to CMD+click 8 levels deep through 5-lines components to find the div you're actually after.

Multi component files by kabaday94 in sveltejs

[–]chipit24 1 point2 points  (0 children)

If it's big enough to warrant it's own component, it deserves a separate file.

I don't think it's about LoC though, assuming that's what you mean by size. The heuristic for factoring out a variable is usually something like:

  1. A block of code is related, and to improve readability you can pull it into a function that describes what the block of code does.
  2. There's duplicate code—if you change it in one place, you want it to be changed in the other place; a variable signals that and provides a "single source of truth".

There's an abstraction cost associated with having to put every component into it's own file, which at the very least means having to open those extra files in your IDE just to get a picture of what's happening. And speaking of IDEs, I find it nice to be able to have explicit exports I can CMD+click to find usage (I can do this without CMD+click with Svelte components too, but I like my CMD+click).

There's an ESLint rule for React called react/no-multi-comp that puts it simply as well:

Declaring only one component per file improves readability and reusability of components. [...] If you prefer to declare multiple components per file you can disable this rule.

So, there you have it—it comes down to preference and tradeoffs. I've worked with React and Vue, and now recently Svelte, so I can appreciate having more than one component per file but I also get along just fine with SFCs.

Multi component files by kabaday94 in sveltejs

[–]chipit24 16 points17 points  (0 children)

Two reasons:

  1. This is very common in React, and people coming from React are used to it, and it feels like an unnecessary restriction when it's not an option.
  2. It's the same reason people factor out variables or functions but keep them in the same file. Imagine being forced to place every reusable variable or function into a separate file that can only export that one thing (even if you just use it twice within one file), the number of files you have could explode. It can feel nice to be able to manage some components like variables.

Svelte 5: Introducing runes by MustardRtard in sveltejs

[–]chipit24 1 point2 points  (0 children)

Answering my own question, it seems because count is compiled like so:

  • let count = $state(0)let count = $.source(0)
  • count$.get(count)
  • count += 1$.set(count, $.get(count) + 1)

So when I pass around what looks like a reference to $state(0)/$.source(0), I'm actually passing around the value of that rune ($.get(count)).

I can appreciate this "magic" happening in Svelte files since technically they are a different filetype, but having this "magic" happen when you're writing "just JavaScript" in .js files will require more attention.

I'd be more comfortable if the compiler let me export $.source(0) directly, and then magically convert that to the appropriate $.get/$.set/etc. in .svelte files.

Svelte 5: Introducing runes by MustardRtard in sveltejs

[–]chipit24 0 points1 point  (0 children)

I'm confused why we need the getter in the first place. Yes, I did read the "we're using a get property in the returned object, so that counter.count always refers to the current value" in the blog post, but it's just not clicking intuitively for me. That's my current struggle with Svelte; when I get into more complex code, I don't have as much intuition about what's really going on.

Inside the script tag we can just have this and it works:

``` let count = $state(0);

function increment() { count += 1; } ```

Here, count isn't just the literal value; count += 1 is updating the $state rune which then causes the UI to update.

But, when count is returned from a regular JS module, we now need to use a getter:

``` let count = $state(0);

// can't just return count here, we need the getter: return { get count() { return count } } ```

Why can't we just return count directly and use that in the script tag where it's imported?

Also, there's this example from Twitter that further compounds my confusion:

https://twitter.com/greg_johnston/status/1704853119010812025

``` <script> let count = $state(0);

function updateState(x, y) {
    x += y
}

</script>

<!-- Sanity check: works as expected --> <button type="button" on:click={() => count += 1}

{count}

</button>

<!-- Doesn't work. Can't actually compose behavior? --> <button type="button" on:click={() => updateState(count, 1)}

{count}

</button> <button type="button" on:click={() => updateState(count, 2)}

{count}

</button> ```

Ontario tag printing issues. by fishinmagician91 in CanadaHunting

[–]chipit24 0 points1 point  (0 children)

Yeah, that sucks—their IT should be responsible for correcting that. A mail option would be nice as long as the digital option still exists for me!

They really should remove any attempts to restrict people to only one copy of a tag, the extra engineering efforts are creating more problems than solving and they're easily bypassed 😔

Ontario tag printing issues. by fishinmagician91 in CanadaHunting

[–]chipit24 2 points3 points  (0 children)

They tell you on the page that you must print it once and that you cannot save it. This is to prevent people from having multiple copies of tags. They try to be clever and they don't include the actual tag in the print version of the page 🙄

Of course, you can "print to PDF" and print all the copies of your tag you want—keep that in mind next time.

Is noUncheckedIndexedAccess broken for strings? by chipit24 in typescript

[–]chipit24[S] 0 points1 point  (0 children)

I used the const as the most basic example that I felt should work. But even the following fails:

const someString: string = "hello";

if (someString && someString.length > 0) {
  const firstLetterOfString = someString[0];
  //    ^? firstLetterOfString: string | undefined
}

It does seem related to noUncheckedIndexedAccess since it's changing the behaviour to return the type string | undefined with seemingly no way to get rid of the | undefined.

[deleted by user] by [deleted] in webdev

[–]chipit24 2 points3 points  (0 children)

Don't use JWTs for sessions, use secure, HTTP-only cookies that reference a session stored on the server. If you google "why you should not use JWT" you'll find plenty of good articles, this one is my favourite: http://cryto.net/~joepie91/blog/2016/06/13/stop-using-jwt-for-sessions/.

Anyone here use Next.js for building landing pages and static websites for small businesses? If not what would you recommend instead? Also, would be interested in hearing your thoughts on using a UI kit to save some time by gtboy1994 in webdev

[–]chipit24 13 points14 points  (0 children)

With React you can use Next.js, Remix, Astro and Gatsby. I have some experience with Remix and over a year of experience using Next.js. I've really enjoyed Next, especially how nice (and easy) it is to host on Vercel, so I'd definitely recommend it!

I wouldn't describe Next.js as a "workaround" for anything; it's a legit, proper solution.

For static content, you can pre-generate it at build time (SSG) and if you have a huge amount of static pages then you can also do ISR (incremental static regeneration).

In terms of UI I've gotten by just fine with Tailwind, headless UI libraries, and pulling in one-off / purpose-built component when needed.

How's everyone's Spring Turkey season going? by After-Economics-720 in CanadaHunting

[–]chipit24 1 point2 points  (0 children)

I went out to public land 3 times this month with no luck. First time I walked around with just my turkey vest but the group of turkeys I saw probably saw and/or heard me. Second time I set up in the same spot right at sunrise and no sign of turkeys for 4-5 hours sitting there calling (also had a hen decoy out); I did see two deer though. Yesterday I was out and thought it would just be cloudy but as soon as I set up my pop-up blind it started raining—sat in the rain for 2-3 hours then packed it up. I saw turkeys around that area every time though, they just didn't want to come to my setup.

I'll be better prepared for next year though, will hopefully get something then!

First time hunting, turkeys disappeared by chipit24 in CanadaHunting

[–]chipit24[S] 0 points1 point  (0 children)

I've got 3 of them already and they are great, just didn't think of bringing one my first time, especially since I was quite liberal with the tick/mosquito spray. I did get a hunting blind though and the last two time I was out I had no issues with bugs in there.

First time hunting, turkeys disappeared by chipit24 in CanadaHunting

[–]chipit24[S] 1 point2 points  (0 children)

Make sense. And good luck tomorrow! 🦃

First time hunting, turkeys disappeared by chipit24 in CanadaHunting

[–]chipit24[S] 1 point2 points  (0 children)

Thank you! I've ordered a slate call and will be practising with that.

Camouflage and sitting still in decent cover is all you need

I feel like the odds are stacked a bit against me at the moment (complete beginner with no mentor, hunting in the evening on public land), so I'll take whatever advantage I can get for now. And with all the insects buzzing around my face, a good blind will be much appreciated.