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

refactor(auth): NASS-1534: Add new auth package and move central code over #7195

Open
wants to merge 29 commits into
base: main
Choose a base branch
from

Conversation

tcodling
Copy link
Contributor

Changes

Add a brief description of the changes in this PR to help give the reviewer context.

Deploys

  • Deploy to Tamanu Internal

Remember to...

  • ...write or update tests
  • ...add UI screenshots and testing notes to the Linear issue
  • ...add any manual upgrade steps to the Linear issue
  • ...update the config reference, settings reference, or any relevant runbook(s)
  • ...call out additions or changes to config files for the deployment team to take note of

@tcodling tcodling changed the title Nass 1534 dry up auth between servers NASS-1534: Add new auth package and dry up code between servers Feb 13, 2025
@tcodling tcodling changed the title NASS-1534: Add new auth package and dry up code between servers refactor(auth): NASS-1534: Add new auth package and dry up code between servers Feb 13, 2025
@tcodling tcodling changed the title refactor(auth): NASS-1534: Add new auth package and dry up code between servers refactor(auth): NASS-1534: Add new auth package and move central code over Feb 14, 2025
deviceId,
},
{
where: {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was throwing type error and I think (still to test) should work without

// Send some additional data with login to tell the user about
// the context they've just logged in to.
res.send({
token,
refreshToken,
user: convertFromDbRecord(stripUser(user.get({ plain: true }))).data,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stripuser was stripping password which covertFromDbRecord does anyway

Comment on lines 18 to 22
asyncHandler(async (req, res) => {
export const refresh = ({ secret, refreshSecret }: { secret: string; refreshSecret: string }) =>
asyncHandler(async (req: any, res): Promise<void> => {
const { body, store } = req;
const { refreshToken, deviceId } = body;

const { canonicalHostName, auth } = config;
const { canonicalHostName, auth } = config as any;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both req and config will need to get their types properly handled but seems out of scope of this card

@dannash100 dannash100 force-pushed the nass-1534-dry-up-auth-between-servers branch from 38133bc to 285ce2e Compare February 16, 2025 22:35
@tcodling tcodling marked this pull request as ready for review February 19, 2025 20:20
Copy link
Member

@passcod passcod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it!

secret: string;
refreshSecret: string;
getLocalisation: Function;
}) =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the pattern of having an emport interface LoginArgs {...} that's then used where needed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like you could do

export interface AuthArgs {
  secret: string;
  refreshSecret: string;
}

export interface LoginArgs extends AuthArgs {
  getLocalisation: Function<foo>;
}

and the AuthArgs can be used directly by the refresh function as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh yep i got you 🙏

@@ -0,0 +1,47 @@
type DbRecord = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think interfaces are prefered over typedefs in ts style

"target": "es2020"
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OOS but we should really consider moving a bunch of those settings to be defaults in the common file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants