-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move initial oauth user profile logic
- Loading branch information
Showing
7 changed files
with
112 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Tegonal CV Manager | ||
|
||
This is a customised Payload 3 App for managing your company's CVs. | ||
|
||
## License | ||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
56 changes: 34 additions & 22 deletions
56
src/payload/collections/Users/hooks/recordSelectedOrganisation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/payload/collections/Users/hooks/userDefaultsAfterCreate.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { CollectionAfterChangeHook } from 'payload'; | ||
import { User } from '@/types/payload-types'; | ||
import { ROLE_USER } from '@/payload/utilities/constants'; | ||
import { Users } from '@/payload/collections/Users'; | ||
|
||
export const userDefaultsAfterCreate: CollectionAfterChangeHook<User> = async ({ | ||
collection, | ||
doc, | ||
req, | ||
operation, | ||
}) => { | ||
if (collection.slug !== Users.slug) { | ||
req.payload.logger.warn({ msg: `Skipping defaultsAfterCreate hook for ${collection.slug}` }); | ||
} | ||
|
||
if (operation === 'create') { | ||
const { roles, organisations, selectedOrganisation } = doc; | ||
let updatedDoc = doc; | ||
|
||
if (!roles || roles.length === 0) { | ||
req.payload.logger.info({ msg: 'Setting default role to user' }); | ||
await req.payload.update({ | ||
id: doc.id, | ||
collection: 'users', | ||
data: { | ||
roles: [ROLE_USER], | ||
}, | ||
req, | ||
}); | ||
} | ||
|
||
if (!organisations || organisations.length === 0) { | ||
req.payload.logger.info({ msg: 'Setting default organisation to 1' }); | ||
updatedDoc.organisations = [ | ||
{ | ||
organisation: 1, | ||
roles: [ROLE_USER], | ||
}, | ||
]; | ||
await req.payload.update({ | ||
id: doc.id, | ||
collection: 'users', | ||
data: { | ||
organisations: [ | ||
{ | ||
organisation: 1, | ||
roles: [ROLE_USER], | ||
}, | ||
], | ||
}, | ||
req, | ||
}); | ||
} | ||
|
||
if (!selectedOrganisation) { | ||
req.payload.logger.info({ msg: 'Setting default selected organisation to 1' }); | ||
await req.payload.update({ | ||
id: doc.id, | ||
collection: 'users', | ||
data: { | ||
selectedOrganisation: 1, | ||
}, | ||
req, | ||
}); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters