Blog

Thoughts, tutorials, and stories from my journey

How Does Society influence Your Future - by Rohit Dudi (all research/scientific/survey claims Direct links)

Asch conformity experiment (1951): https://scispace.com/papers/effects-of-group-pressure-upon-the-modification-and-4go5lj9r9o Festinger — Social Comparison Theory (1954): https://www2.psych.ubc.ca/~schaller/528Readings/Festinger1954.pdf Peer influence peaks in adolescence (inverted-U / peak ~14): https://pmc.ncbi.nlm.nih.gov/articles/PMC2779518/ Moving to Opportunity — Neighborhood effects on child outcomes (Chetty et al.): https://opportunityinsights.org/wp-content/uploads/2018/03/mto_paper.pdf Family income → brain structure in children (Noble et al. 2015): https://www.nature.com/articles/nn.3983 SES effects on IQ / cognitive development (longitudinal evidence): https://pmc.ncbi.nlm.nih.gov/articles/PMC4641149/ More than 90% of children breathe polluted air (WHO): https://www.who.int/news/item/29-10-2018-more-than-90-of-the-worlds-children-breathe-toxic-air-every-day Social relationships and mortality risk (meta-analysis — Holt-Lunstad et al. 2010): https://journals.plos.org/plosmedicine/article?id=10.1371/journal.pmed.1000316 Loneliness comparable to smoking ~15 cigarettes/day (Surgeon General / Holt-Lunstad): https://www.hhs.gov/sites/default/files/surgeon-general-social-connection-advisory.pdf Loneliness and social isolation → increased CVD and stroke risk: https://pubmed.ncbi.nlm.nih.gov/27091846/ Loneliness associated with higher dementia risk (meta-analyses): https://www.ncbi.nlm.nih.gov/pmc/articles/PMC9751343/ Childhood social isolation → long-term adult mental and physical health effects: https://jamanetwork.com/journals/jamapediatrics/fullarticle/205331 Toxic workplace prevalence and mental health impact (APA surveys): https://www.apa.org/news/press/releases/2023/07/work-mental-health-challenges Hidden curriculum and institutional conformity (education sociology reviews): https://www.scopus.com/record/display.uri?eid=2-s2.0-85129302173&origin=inward Poverty, chronic stress, cortisol, and neurodevelopment pathways: https://www.nature.com/articles/s41398-022-02178-4 Environmental enrichment increases neurogenesis (animal studies): https://pmc.ncbi.nlm.nih.gov/articles/PMC11196820/ COVID-19 social isolation effects on youth mental health: https://www.jaacap.org/article/S0890-8567(20)30337-3/fulltext Loneliness prevalence in adults and global population (CDC/WHO): https://www.cdc.gov/social-connectedness/risk-factors/index.html

Rohit dudiRohit dudi researchrohit dudi research paper
Read More

Refresh And Access Tokens in Software Backend on a server

Refresh Token is usually a long duration (days or months) token that is used to provide a new access token to a user after expiring their short duration (some hours or days) Access token. and refresh token is stored in user database schema to authenticate and authorize the request, and Both refresh token and access tokens are encrypted and store the user ID in itself. Encryption and decryption of tokens is done by SECRET_ENVIRONMENT_VARIABLES using any secure library with Efficient cryptography algorithms. while generating the new access token for user after authentication, the refresh token is also regenerated and changed in user database schema and both tokens are returned to user through secure cookies (it can only changed on server side). Here is a javascript code example to understand how we regenerate the access and refresh token- Javascript Code example to understand refresh token and access token const refreshTheAccessToken = asyncHandler(async (req, res) => { // extract the refreshToken const incomingRefreshToken = req.cookies?.refreshToken || req.body.refreshToken; // if it is not than it's a bad request if (!incomingRefreshToken) { throw new ApiError(300, "Unathorized request"); } // decode the refresh token using secure environment variables const decodedRefreshToken = jwt.verify( incomingRefreshToken, process.env.REFRESH_TOKEN_SECRET ); // while genearting the token i have already included the _id of user // using id find the user by database query and remove the sensitive data const requesterUser = await User.findById(decodedRefreshToken._id) // if user not found than obviously refresh token is invalid if (!requesterUser) { throw new ApiError(400, "invalid refresh token"); } // if the incoming refresh token is matching with existing refresh token of current user in databse than if (requesterUser.refreshToken == incomingRefreshToken) { // after authentication // tryCatch is a good practice for error handling and optional chaining try { // i have already created a method to generate new tokens // cause i also use this method for login Endpoint // passing the _id it will inject the new refresh token in user schema const { accessToken, refreshToken } = generateAccessAndRefreshTokens(requesterUser._id); // options for cookies (server side changable only) const options = { httpOnly: true, secure: true }; // after regenerating the tokens and changing on user schema // restore the user in a new variable for updated data while removing the sensitive data const loggedInUser = await User.findById(requesterUser._id).select( "-password -refreshToken" ); // now return the response by method chaining return res .status(200) .cookie("accessToken", accessToken, options) .cookie("refreshToken", refreshToken, options) .json( // (i am using) ApiResponse is a utility function that extends the api response class in node.js new ApiResponse( 200, { user: loggedInUser, accessToken, refreshToken }, "Access token refreshed successfully" ) ); } catch (error) { // this one is easy peasy as well throw new ApiError(400, error.message || "Error generating tokens"); } } else { // if not matched throw new ApiError(200, "refresh token is expired or used."); } }); remember this is my algorithm to achieve this particular functionality You can always do it better and optimize efficiently. thanks for reading this article, i hope this was really easy explained. I am Rohit keep reading my easy explained articles. how the refresh and access tokens works?

refresh tokenaccess tokenrefresh tokens
Read More