-
Notifications
You must be signed in to change notification settings - Fork 25
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
[BUG]: getRepository 'typeorm' is deprecated #37
Comments
I found an alternative: |
Closing |
Hi, sorry for the late reply. I'm reopening this issue as a memo to fix it, but a correct implementation would now be (this is how I set everything up in the index file): import { DataSource, DataSourceOptions } from 'typeorm';
import { TypeormStore } from 'connect-typeorm';
import { Session } from './entity/Session';
import express from 'express';
import ExpressSession from 'express-session';
// Define express variable
const app = express();
// Create an exportable `TypeormStore` to allow access everywhere
export const sessionStore = new TypeormStore({
cleanupLimit: 2,
limitSubquery: false, // If using MariaDB.
ttl: 86400,
})
// Create an exportable `DataSource` to allow `getRepository()` access everywhere.
// `databaseOptions` is an object of type DataSourceOptions and may depend on your configuration/needs.
export const dataSource = new DataSource(databaseOptions);
// Initialize DataSource
dataSource.initialize()
.then(async () => {
const sessionRepository = dataSource.getRepository(Session);
app.use(
ExpressSession({
resave: false,
saveUninitialized: false,
store: sessionStore.connect(sessionRepository),
// Cookie settings can be added here based on your configuration/needs.
// See: https://expressjs.com/en/resources/middleware/session.html
secret: 'keyboard cat' // This should not be hardcoded, an .env variable is preferred.
})
);
/* Everything else required by your app: setting up routes, starting server on HTTP/S, etc... */
}).catch((error) => console.log(error)); |
But it is not working with NestJS. If possible, please provide an example of using it in the NestJS |
Yeah, that's an example configuration for an Express backend. I yet have to try running it in Nest. In the meanwhile, please refer to this https://docs.nestjs.com/techniques/session for how to set up a session middleware, it should point you in the right direction. |
tried this too its running fine with no issues but. data is not getting saved. |
I may have some time this week or next to look at it, could you please share a repo with the implementation? |
If you're using it with nest.js, you can do it this way
|
Contact Details
No response
Bug description
The documentation for connect-typeorm shows the session store connection being set to the entity repository from the depreciated TypeORM getRepository method. Is there a replacement for getRepository or a workaround for this issue?
Steps to reproduce
See documentation (README.md) for this repository.
Additional Information
No response
The text was updated successfully, but these errors were encountered: