-
Notifications
You must be signed in to change notification settings - Fork 6k
Durante o processo de logout de uma instância, as chaves associadas a… #2191
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
Changes from 1 commit
be57609
45e461e
b6620d2
48625a7
4d2a189
feff038
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -39,7 +39,11 @@ import { Logger } from '@config/logger.config'; | |||||||||||||||||||||||||||||||||||||
| import { AuthenticationCreds, AuthenticationState, BufferJSON, initAuthCreds, proto, SignalDataTypeMap } from 'baileys'; | ||||||||||||||||||||||||||||||||||||||
| import { isNotEmpty } from 'class-validator'; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| export type AuthState = { state: AuthenticationState; saveCreds: () => Promise<void> }; | ||||||||||||||||||||||||||||||||||||||
| export type AuthState = { | ||||||||||||||||||||||||||||||||||||||
| state: AuthenticationState; | ||||||||||||||||||||||||||||||||||||||
| saveCreds: () => Promise<void> | ||||||||||||||||||||||||||||||||||||||
| removeCreds: () => Promise<void>; | ||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| export class AuthStateProvider { | ||||||||||||||||||||||||||||||||||||||
| constructor(private readonly providerFiles: ProviderFiles) {} | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -86,6 +90,19 @@ export class AuthStateProvider { | |||||||||||||||||||||||||||||||||||||
| return response; | ||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const removeCreds = async () => { | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const [response, error] = await this.providerFiles.removeSession(instance); | ||||||||||||||||||||||||||||||||||||||
| if (error) { | ||||||||||||||||||||||||||||||||||||||
| // this.logger.error(['removeData', error?.message, error?.stack]); | ||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+93
to
+98
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (bug_risk): removeCreds swallows errors silently; consider logging or surfacing them. Errors from providerFiles.removeSession are currently ignored. If downstream consumers rely on error handling, log or propagate these errors.
Suggested change
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| logger.info({ action: 'remove.session', instance }); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const creds: AuthenticationCreds = (await readData('creds')) || initAuthCreds(); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -126,6 +143,10 @@ export class AuthStateProvider { | |||||||||||||||||||||||||||||||||||||
| saveCreds: async () => { | ||||||||||||||||||||||||||||||||||||||
| return await writeData(creds, 'creds'); | ||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| removeCreds | ||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const logger = new Logger('useMultiFileAuthStatePrisma'); | ||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,6 +8,7 @@ export async function useMultiFileAuthStateRedisDb( | |||||||||||||||||||||||||||||||
| ): Promise<{ | ||||||||||||||||||||||||||||||||
| state: AuthenticationState; | ||||||||||||||||||||||||||||||||
| saveCreds: () => Promise<void>; | ||||||||||||||||||||||||||||||||
| removeCreds: () => Promise<void>; | ||||||||||||||||||||||||||||||||
| }> { | ||||||||||||||||||||||||||||||||
| const logger = new Logger('useMultiFileAuthStateRedisDb'); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
@@ -36,6 +37,17 @@ export async function useMultiFileAuthStateRedisDb( | |||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| async function removeCreds(): Promise<any> { | ||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| logger.warn({ action: 'redis.delete', instanceName }); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| return await cache.delete(instanceName); | ||||||||||||||||||||||||||||||||
| } catch { | ||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
Comment on lines
+41
to
+47
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Consider using logger.info for successful deletion and logger.warn only for errors. Use logger.info to indicate successful deletion, and reserve logger.warn or logger.error for error cases to improve log clarity.
Suggested change
|
||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
Comment on lines
+40
to
+48
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (code-quality): Avoid function declarations, favouring function assignment expressions, inside blocks. ( ExplanationFunction declarations may be hoisted in Javascript, but the behaviour is inconsistent between browsers. Hoisting is generally confusing and should be avoided. Rather than using function declarations inside blocks, you should use function expressions, which create functions in-scope. |
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| const creds: AuthenticationCreds = (await readData('creds')) || initAuthCreds(); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||
|
|
@@ -76,5 +88,7 @@ export async function useMultiFileAuthStateRedisDb( | |||||||||||||||||||||||||||||||
| saveCreds: async () => { | ||||||||||||||||||||||||||||||||
| return await writeData(creds, 'creds'); | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| removeCreds | ||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (code-quality): Avoid function declarations, favouring function assignment expressions, inside blocks. (
avoid-function-declarations-in-blocks)Explanation
Function declarations may be hoisted in Javascript, but the behaviour is inconsistent between browsers. Hoisting is generally confusing and should be avoided. Rather than using function declarations inside blocks, you should use function expressions, which create functions in-scope.