graphile / starter

Opinionated SaaS quick-start with pre-built user account and organization system for full-stack application development in React, Node.js, GraphQL and PostgreSQL. Powered by PostGraphile, TypeScript, Apollo Client, Graphile Worker, Graphile Migrate, GraphQL Code Generator, Ant Design and Next.js
https://graphile-starter.herokuapp.com
Other
1.73k stars 218 forks source link

How can we manage session in the postgraphile app? #296

Closed raviSussol closed 2 years ago

raviSussol commented 2 years ago

Summary

Hi, I'm new to the Postgraphile and I've just started looking at this starter kit to know about how the session is managed in this postgraphile app. I saw there are 2 tables being used for a session management in this starter kit, 1. connect_pg_simple_sessions 2. sessions. And I've seen that the sessions table gets updated in every valid graphql request made to the database which keeps track of user that made request and his/her last active time. Also it has been used to track user login while login request is made through login function in the database where on successful login a new record is inserted into this table. But the connect_pg_simple_sessions table has just been used or initialized at the time of middleware setup on the server. So my question is if we're using the sessions table to track user logins and every graphql request made by user then what is the use of connect_pg_simple_sessions table within the app? How can we track user's session after their login like we normally do in normal express js app using any session library (i.e. like this conect pg simple for instance)? How can we send session inside a cookie to the user after user logs in in the postgraphile app?

Additional context

Trying to understand the session management logic flow in the postgraphile with the help of this starter kit so no additional context but some above questions.

benjie commented 2 years ago

what is the use of connect_pg_simple_sessions table within the app

You don't need it; it's only there in case you don't want to use the redis session provider (or provide your own).

How can we track user's session after their login like we normally do in normal express js app using any session library (i.e. like this conect pg simple for instance)?

You can do it like you normally do in a normal express js app using any session library. You can replace the session store with whatever you want:

https://github.com/graphile/starter/blob/a69cf6b1bb22d236e297ce23e5a0d1658b1e6d80/%40app/server/src/middleware/installSession.ts#L30-L56

[semi-automated message] Thanks for your question; hopefully we're well on the way to helping you solve your issue. This doesn't currently seem to be a bug in the library so I'm going to close the issue, but please feel free to keep requesting help below and if it does turn out to be a bug we can definitely re-open it 👍

You can also ask for help in the #help-and-support channel in our Discord chat.