Class: AuthService
Defined in: packages/web-backend/src/auth/auth.service.ts:13
Service for user authentication and JWT token management. Handles credential verification and token issuance/refresh.
Constructors
Constructor
new AuthService(
collabService,jwtService):AuthService
Defined in: packages/web-backend/src/auth/auth.service.ts:19
Construct the authentication service with collaborators.
Parameters
collabService
Service for user persistence and last-login updates.
jwtService
JwtService
NestJS JWT service for signing and verifying tokens.
Returns
AuthService
Methods
getJwtToken()
getJwtToken(
user):Promise<{token:string; }>
Defined in: packages/web-backend/src/auth/auth.service.ts:58
Generates a JWT token for the authenticated user.
- After the Local Strategy verifies the User credentials, the User object is sent to getJwtToken() method.
- The userID, username, and email are extracted from the User object. Then a JWT is generated against these data.
Parameters
user
User object extracted from the request headers
Returns
Promise<{ token: string; }>
JWT token
loginUser()
loginUser(
username,password):Promise<User>
Defined in: packages/web-backend/src/auth/auth.service.ts:35
Authenticates a user by username and password.
- The Local Strategy (AuthGuard('local')) sends the User credentials to loginUser() method.
- The loginUser() method checks if the User exists in the database using the CollabService.loginUser() method.
- If the User exists, then the password is verified as well.
Parameters
username
string
Username string
password
string
Password string
Returns
Promise<User>
A mongoose document of the user or throws 401 HTTP status
updateJwtToken()
updateJwtToken(
refreshToken):Promise<{token:string; }>
Defined in: packages/web-backend/src/auth/auth.service.ts:78
Refresh an access token using a valid refresh token.
Parameters
refreshToken
string
A previously issued refresh token used to mint a new access token.
Returns
Promise<{ token: string; }>
Object containing a new token when the refresh token is valid.
Throws
Error when the token is invalid or verification fails.
verifyPassword()
verifyPassword(
username,password):Promise<boolean>
Defined in: packages/web-backend/src/auth/auth.service.ts:122
Simple function that checks if the password is correct or not (Used for verification purposes)
Parameters
username
string
username of the user
password
string
password of the user
Returns
Promise<boolean>
