Skip to content

Commit

Permalink
squash! PATCH: Authenticate via SAPI email/password in Login Form
Browse files Browse the repository at this point in the history
RC 6.6.0 dropped jQuery as a dependency, so replace
jQuery’s `$.post().done()` with the standard Fetch API’s
`fetch().then()`
  • Loading branch information
nmagedman committed May 9, 2024
1 parent ea06ab7 commit 957b51b
Showing 1 changed file with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,36 @@ const AuthenticationProvider = ({ children }: AuthenticationProviderProps): Reac
loginWithPassword: (user: string | { username: string } | { email: string } | { id: string }, password: string): Promise<void> =>
new Promise((resolve, reject) => {
console.log(`Login via SAPI: Authenticating with email='${user}' password='${password}'`);
$.post(

const params = new FormData();
params.append("email", user);
params.append("password", password);

fetch(
`${location.origin.replace('rc.', '')}/authentication/rocketchat_email_password_login`,
{ email: user, password },
).done((response) => {
if (response.error) {
console.log(`Login via SAPI: Error: ${response.error}`);
reject(new Error(response.error));
} else {
console.log(`Login via SAPI: Received Token: ${response.rc_token}`);
Meteor.loginWithToken(response.rc_token, (error) => {
if (error) {
console.log(`Login via SAPI: Token rejected: ${error.message}`, error);
reject(new Error('Auth Token received from Seeking Alpha is not valid'));
} else {
resolve();
}
});
}
})
{
method: "POST",
body: params,
cache: "no-cache",
},
)
.then((response) => response.json())
.then((data) => {
if (data.error) {
console.log(`Login via SAPI: Error: ${data.error}`);
reject(new Error(data.error));
} else {
console.log(`Login via SAPI: Received Token: ${data.rc_token}`);
Meteor.loginWithToken(data.rc_token, (error) => {
if (error) {
console.log(`Login via SAPI: Token rejected: ${error.message}`, error);
reject(new Error('Auth Token received from Seeking Alpha is not valid'));
} else {
resolve();
}
});
}
});
}),
/* eslint-enable prettier/prettier */
loginWithService: <T extends LoginServiceConfiguration>(serviceConfig: T): (() => Promise<true>) => {
Expand Down

0 comments on commit 957b51b

Please sign in to comment.