Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
raviSussol opened this issue Jan 29, 2022 · 1 comment
Closed

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

raviSussol opened this issue Jan 29, 2022 · 1 comment
Labels
question Further information is requested

Comments

@raviSussol
Copy link

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 benjie added the question Further information is requested label Feb 1, 2022
@benjie
Copy link
Member

benjie commented Feb 1, 2022

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:

const store = process.env.REDIS_URL
? /*
* Using redis for session storage means the session can be shared across
* multiple Node.js instances (and survives a server restart), see:
*
* https://medium.com/mtholla/managing-node-js-express-sessions-with-redis-94cd099d6f2f
*/
new RedisStore({
client: redis.createClient({
url: process.env.REDIS_URL,
}),
})
: /*
* Using PostgreSQL for session storage is easy to set up, but increases
* the load on your database. We recommend that you graduate to using
* redis for session storage when you're ready.
*/
new PgStore({
/*
* Note even though "connect-pg-simple" lists "pg@7.x" as a dependency,
* it doesn't `require("pg")` if we pass it a pool. It's usage of the pg
* API is small; so it's compatible with pg@8.x.
*/
pool: rootPgPool,
schemaName: "app_private",
tableName: "connect_pg_simple_sessions",
});

[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.

@benjie benjie closed this as completed Feb 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants