Skip to content

Commit

Permalink
fix(express-session-mikro-orm): fix update query for mongodb (#108)
Browse files Browse the repository at this point in the history
use nativeUpdate instead of persist and flush for session update

fix #107
  • Loading branch information
bahdcoder authored Jun 17, 2021
1 parent 73e16a7 commit b7b0a22
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 8 deletions.
Binary file added examples/blog/example_bloggg
Binary file not shown.
4 changes: 3 additions & 1 deletion examples/blog/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ tensei()
])
.plugins([
welcome(),
cms().plugin(),
cms()
.plugin(),
auth().rolesAndPermissions().refreshTokens()
// .cookieSessions()
.plugin(),
Expand All @@ -54,6 +55,7 @@ tensei()
])
.databaseConfig({
debug: true,
type: 'mongo'
})
.start()
.catch(console.error)
1 change: 0 additions & 1 deletion packages/components/src/Icon/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const Icon: React.FC<IconProps> = ({
height = 28,
active = false
}) => {
console.log('@@@@@@->', icon)
const iconName = `${toPascalCase(icon)}Icon`

const Icon =
Expand Down
12 changes: 7 additions & 5 deletions packages/express-session-mikro-orm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,16 @@ const StoreFactory = (Store: any, sessionConfig?: SessionConfig) => {
})
.then((session: any) => {
if (session) {
this.orm.em.assign(session, {
const updates = {
data: JSON.stringify(payload),
expires
})
}

return this.orm.em
.persistAndFlush(session)
.then(() => session)
this.orm.em.assign(session, updates)

return this.orm.em.nativeUpdate(this.entityName, {
session_id: session.session_id
}, updates).then(() => session)
}

const newSession = this.orm.em.create(this.entityName, {
Expand Down
2 changes: 1 addition & 1 deletion packages/tests/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const getDatabaseCredentials = () => {

const config: DatabaseConfiguration = {
type: databaseType,
forceUtcTimezone: true
forceUtcTimezone: true,
}

if (databaseType === 'postgresql') {
Expand Down
16 changes: 16 additions & 0 deletions packages/tests/packages/cms/admin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ test('can passwordlessly register a new administrator user', async () => {
orm: { em }
}
} = await setup([cms().plugin(), setupFakeMailer(mailerMock)], false)
await em.nativeDelete('AdminUserSession', {})

const client = (SupertestSession(app) as unknown) as SI<any>

Expand Down Expand Up @@ -48,6 +49,21 @@ test('can passwordlessly register a new administrator user', async () => {

expect(loginResponse.status).toBe(302)
expect(loginResponse.headers['location']).toBe('/cms')

const session = await em.find<{
data: string
}>('AdminUserSession', {})

const authUser = await em.findOne<{
id: string,
email: string
}>('AdminUser', {
email
})

const sessionData = JSON.parse(session[0].data)

expect(sessionData?.user?.id?.toString()).toBe(authUser.id.toString())
})

test('cannot register another administrator if a super admin already exists', async () => {
Expand Down

0 comments on commit b7b0a22

Please sign in to comment.