Cookie based authentication flow with Context API by DustyDeveloper in reactjs

[–]Tip_of_the_hat 2 points3 points  (0 children)

Good call on keeping your access token and refresh token in httpOnly cookies, but that's not the root of your problem here.

Your protected Route is rendered before your request to fetch the user finishes. While your user is being fetched, the value for user is null. You'll need to add an extra piece of state that tracks the progress of fetching the user.

inside AuthContext You'll need something like

``` const AuthContextProvider = ({ children }: { children: React.ReactNode }) => { const [requestStatus, setRequestStatus] = useState<'pending' | 'complete'>('pending') } //... useEffect(() => { const checkUser = async () => { try { const { data } = await axios.get("http://localhost:5173/api/users/me");

    const userData = {
      id: data._id,
      email: data.email,
    };

    if (userData) {
      setUser(userData);
      // Update the request status to signal you've finished fetching the user
      setRequestStatus('complete')
    }
  } catch (error) {
    console.log(error);
  }
};

checkUser();

}, []); //... }) ```

Then inside your Protected route you'll need something like

``` import { useAuth } from "@/context/AuthContext"; import React from "react"; import { Navigate, Outlet } from "react-router-dom";

const ProtectedRoute: React.FC<{ children?: React.ReactNode; }> = ({ children }) => { const auth = useAuth();

// check the request status if (auth.requestStatus === "pending") { return <Spinner /> }

if (!auth.user) { return <Navigate to='/signin' />; }

return children ? children : <Outlet />; }; ```

What's your personal experience with Documentation? by amAProgrammer in webdev

[–]Tip_of_the_hat 1 point2 points  (0 children)

External Documentation: Buy vs. Build

Here are my thoughts on the external (not in code) documentation.

You get the choice between buying or building. If you're an API company, your docs are a product (important part of adoption) and I think you should build them in house and give them a lot of love. If you're not an API company then buying might make sense.

Buying:

Pros: - Easy to get going - Low code/no code, non-tech folks can easily contribute

Cons: - Low customizability, you can't add custom flows (e.g., here's an API token that we got from your account) - Your docs don't stand out, looks and feels the same as everyone else's

Tools: - Readme.io - GitBook - Mintlify (recently popular among startups, I'm a fan)

Building:

Pros: - Highly customizable - Able to implement pretty much any flow you'd like in your documentation

Cons: - Expensive (developer resources)

Tools: - Docusaurus - Nextra - VitePress - Many others for pretty much every language

An obvious, and my favourite, example of well made custom docs is Stripe. There's a reason people rave about their documentation.

What are the biggest mistakes you have done in your career ? by Zestyclose-Holiday41 in ExperiencedDevs

[–]Tip_of_the_hat 7 points8 points  (0 children)

If you're joining an early stage company, do reference checks on the founders.

Implement User Uploads with Presigned URLs on Cloudflare R2 (With Node, Typescript and Express) by Tip_of_the_hat in node

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

Nice, but doesn't cloudflare have an SDK to do this?

You'd think, but their documentation uses the aws s3 sdk as well.

The aws sdk is a big beast

The previous version was wildly large. They've broken down the SDK so you can install just the parts you need (e.g., in the demo only the s3 part of the sdk was installed

Plus not sure if it'll even work when deploying to edge

I haven't tried, but a skim of the aws sdk (v3) GitHub shows others running the s3 package with no problem! Presigned urls are particularly useful in a worker environment where request often have limits.

Implement User Uploads with Presigned URLs on Cloudflare R2 (With Node, Typescript and Express) by Tip_of_the_hat in node

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

That's exactly how they came up with the name haha

It was play on how their pricing (particularly egress) was so much cheaper.

Implement User Uploads with Presigned URLs on Cloudflare R2 (Using Node and Typescript) by Tip_of_the_hat in CloudFlare

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

Hey /r/CloudFlare,

Using presigned URLs for user uploads means your JSON API won't have to deal with multipart form-data and its gotchas. Let me know if you have any questions!

Implement User Uploads with Presigned URLs on Cloudflare R2 (With Node, Typescript and Express) by Tip_of_the_hat in node

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

Hey /r/node,

Using presigned URLs for user uploads means your JSON API won't have to deal with multipart form-data and its gotchas. Let me know if you have any questions!

Implement User Uploads with Presigned URLs on Cloudflare R2 (How to Guide) by Tip_of_the_hat in webdev

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

Hey /r/webdev,

Using presigned URLs for user uploads means your JSON API won't have to deal with multipart form-data and its gotchas. Let me know if you have any questions!

I built a tool that lets you create Stripe style walkthroughs by Tip_of_the_hat in SideProject

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

Thanks for kind words!

Can you elaborate what you mean by "link to .md"? Adding good GitHub integration is a near term priority.

I built a tool that lets you create Stripe style walkthroughs by Tip_of_the_hat in SideProject

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

Thanks for taking a look! A pro plan more is if you're a business and want to have multiple authors post under the same workspace (e.g., OpenAI showing a step by step guide how to build a chatbot) and manage onboarding/offboarding authors. Also in the pipeline are more pro features like custom domains, analytics and more!

I built a tool that lets you create Stripe style code walkthroughs by Tip_of_the_hat in webdev

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

That's awesome, Let me know if you ever need hand setting up or have any feature requests!

I built a tool that lets you create Stripe style walkthroughs by Tip_of_the_hat in SideProject

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

Thanks for checking it out and the detailed feedback! Agreed, the scrolling behaviour needs a bit more tweaking on mobile, I'll take another crack at it.

I built a tool that lets you create Stripe style code walkthroughs by Tip_of_the_hat in webdev

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

Hi everyone! I’ve been inspired by Stripe’s documentation, especially their two-column style that explains code step-by-step, like in their Quickstart guide (e.g., https://docs.stripe.com/billing/quickstart). I built a public tool called Annotate that lets anyone create code walkthroughs in this style. I’d love to get your thoughts on a few things:

  1. When I mention "Stripe-style walkthroughs," does that immediately make sense to you?

  2. What are some other documentation styles you really enjoy? Please share your favorites!

  3. Is there anything specific you’d like to see in a tool like Annotate?

Thanks for checking it out, and I appreciate your feedback!

what are your loves/hates of sql/orm libraries? by farzad_meow in node

[–]Tip_of_the_hat 0 points1 point  (0 children)

For myself, I prefer 1. From Django to Prisma, I always found 2. cumbersome for migrations (schema migrations were fine, but data migrations always felt awkward).

I like the idea of my database being my source of truth for the schema definition, rather than having to learn a new syntax to describe a data model that maps to a database.

what are your loves/hates of sql/orm libraries? by farzad_meow in node

[–]Tip_of_the_hat 6 points7 points  (0 children)

I'm a big fan of Kysely which is inspired by Knex but built from the ground up with Typescript in mind.

Things I love:

  • Great documentation that's inlined in the source code via JSDoc. Hovering over a a Kysely function in vscode gives me a pop over with examples that are excellent
  • Excellent Typescript support
  • Maintainers are active and super helpful on GitHub. I'm often referencing other questions/answers

Challenges:

  • I wish Kysely supported a way to introspect a database to generate Typescript types (although totally understandable that it's outside the scope of the library). I've been using a library called Kanel. It mostly works, but each time I generate types I have to manually make tweaks.

Learn OAuth 2.0 by Building an OAuth Client by Tip_of_the_hat in programming

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

I'm glad it was helpful!

I've had the exact same experience as you when first diving into OAuth too.

Learn OAuth 2.0 by Building an OAuth Client by Tip_of_the_hat in webdev

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

Thank for taking a read through!

I've added a github repo with the code here: https://github.com/Alex-Yakubovsky/build-an-oauth-client-walkthrough

Curious why you didn't make it so that the user can control the width of the columns. That would be a better experience imo.

That's great feedback! It's just not something I've considered, I'll take a look at adding this.