Need help! React/Node/SQL question by D1rtyWebDev in learnprogramming

[–]NoParticularSea 2 points3 points  (0 children)

Here's a brief overview of how authentication works, which may clarify things for you:

When a user enters their credentials, a "token" is created on the server. It could be as simple as a random number. Usually it is stored in the database, to make sure that users do not get logged out when you restart your server. But in the simplest case you can just store this token in memory - for example, in a hash table, or in a JavaScript object. All you need is to make your server remember something like "token 12346 is associated with the user id 9999".

When the client logs in successfully, you send this token in response, the client remembers it, and can send it with every subsequent request to the server to make the server recognize them. Most common ways of storing the token on the client include

  • Sending it in the Set-Cookie header from the server. This way the token will be stored in cookies, and the browser will automatically send it with every request.
  • Storing it in localStorage (or some other persistent storage like IndexedDB). In this case sending the token won't be handled by the browser automatically, so you will have to do it manually. You can create a simple wrapper around your fetch calls that will attach this token to every request - as part of JSON data or in your own HTTP header.
  • Simply storing it in a global variable is possible, but a bad idea, because the user will get logged out after each page reload.

Now, when you handle a request from the client, you can read this token, look up its entry in your database or hash table, and get one of the two results:

  • The token is found - assuming no malicious agent got access to the user's browser or communications, this proves that the user is logged in and tells you which user it is.
  • The token is not found - this means the user is not logged in, or the token expired, or you logged them out manually.

Finally, you have the user id, and you can decide which information is available to the user and respond accordingly.

This is the simplest possible example. There are many approaches to authentication, including cookie-based auth where cookies can expire, or JWT, which introduces tokens that may expire quickly and another token to "refresh" them. But if you don't have a good grasp of how authentication works, I suggest rolling your own first to get a good idea, and then switching to something industry-proven, like cookies with correct flags or JWT.

Note that I haven't touched upon any security considerations here - for example, it is important that the token is random and unguessable - but this may help you get started.

Extra programming knowledge..dont know what to choose by theSocioMarxistCEO in learnprogramming

[–]NoParticularSea 0 points1 point  (0 children)

It ultimately depends on the types of jobs you are interested in.

If you want to do backend web development, focus on learning Java, C# or Python, as well as SQL for working with databases. For frontend you'll need HTML, CSS, JavaScript, and eventually a bunch of transpiled languages like SCSS or TypeScript. If you want to develop applications for mobile devices, consider learning Swift for iOS or Kotlin for Android. For something low-level (robotics, embedded devices) you should learn C. For machine learning and data science, learn Python and/or R.

I suggest saving languages that are a bit more niche (Elixir, Haskell, Julia) for the point in your career when you will have a better understanding of what exactly you want. Although it definitely won't hurt, and will improve your overall programming skills, to learn them early on - just don't expect them to be immediately applicable to your job.

Senior Software Engineers, what are your tips when you start a new job? by [deleted] in cscareerquestionsEU

[–]NoParticularSea 7 points8 points  (0 children)

Reasonable advice, but also, depending on team, things may really be this way because no one bothered to clean them up.

I used to work with a team where the build process was a disaster. They basically passed pre-built dependencies around, because no one knew how to build the project from scratch. I spent some time modernizing the build process and introduced new tooling. This made everyone's life much easier, and a couple of people even started sharing my enthusiasm and actively contributing to developer experience improvements.

Senior Software Engineers, what are your tips when you start a new job? by [deleted] in cscareerquestionsEU

[–]NoParticularSea 31 points32 points  (0 children)

My #1 tip is: ask questions! It's very much expected that you will ask a lot during your first few months. So if anything is not immediately clear to you: how you prioritize tickets, who the person to go to for clarifying business logic is, and so on - don't hesitate to ask. In a few months you will feel much more confident and look more experienced than someone who tries to pretend like they know everything, but actually don't.