Login using custom Authentication adapter #828
Replies: 2 comments 4 replies
-
Cf. osjs-client/src/adapters/ui/login.js#150: create() : Cf. osjs-client/src/auth.js#L216: login() : Cf. osjs-srver/src/auth.js#126: login() : So for your client adapter, try this: |
Beta Was this translation helpful? Give feedback.
-
Use exceptions in order to trigger an error in the process. Also, you need to resolve your promise in order for the UI to respond :) async login(values) {
// You can transform the form values from login here if you want
const username = values.username;
const password = values.password;
console.log(values);
if (!username || !password) {
throw new Error("Please provide a username and a password.");
}
return fetch("https://jsonplaceholder.typicode.com/posts", {
method: "POST",
body: JSON.stringify({
title: username,
body: password,
userId: 1,
}),
headers: {
"Content-type": "application/json; charset=UTF-8",
},
})
.then((response) => response.json())
.then((json) => {
console.log(json);
return json;
});
} or: async login(values) {
// You can transform the form values from login here if you want
const username = values.username;
const password = values.password;
console.log(values);
if (!username || !password) {
throw new Error("Please provide a username and a password.");
}
const response = await fetch("https://jsonplaceholder.typicode.com/posts", {
method: "POST",
body: JSON.stringify({
title: username,
body: password,
userId: 1,
}),
headers: {
"Content-type": "application/json; charset=UTF-8",
},
})
const json = await response.json()
console.log(json);
return json;
} |
Beta Was this translation helpful? Give feedback.
-
Hello all,
I generated a new adapter using
npm run make:auth
and updated it with the content below:With this adapter, when a user clicks the submit button:
return false;
statement, but that didn't change anything.How do I then implement my custom login? What am I missing or doing wrong? The links provided for more details on how to do that as indicated in the file above are inaccessible:
Beta Was this translation helpful? Give feedback.
All reactions