Will sk-auth work with strapi? #44
-
Hello I'm currently using Strapi headless cms. It has a feature of providing various auth providers, and this also relates to accessing cms content. I'm interested to understand better if this is an alternative to, or complimentary to the strapi auth mechanism. https://strapi.io/documentation/developer-docs/latest/guides/auth-request.html#setup Thanks for your help, and for enhancing the svelte ecosystem. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi there! Thank you for opening this discussion page, I haven't personally used or setup a Strapi CMS backend with authentication myself yet, but it's something I will consider creating an example for this project when I get around to it. In any case, SK-auth is customizable and well-equipped to handle all sorts of authentication flows, so Strapi's standard JWT implementation shouldn't be an issue. I gave the documentation a look on the auth setup, and it looks like Strapi has a pretty simple login/auth flow. So my proposal would be to create the following provider in SK-auth and then just storing the JWT in the SK session so you can retrieve it from the frontend/client and use it to make requests. Custom ProviderYou'll need to make a custom provider that extends from the SK-auth generic class StrapiProvider extends Provider {
constructor(config: ProviderConfig) {
super({
// This line is important to make the `api/auth/strapi/<signin|callback>` endpoints work and tells signIn() which endpoint to use
id: "strapi",
});
}
async callback({ body }: ServerRequest) {
const { username, password } = body;
const res = await fetch("http://localhost:1337/auth/local", {
method: "POST",
body: JSON.stringify({
password,
identifier: username,
}),
});
const profile = await res.json();
return [profile, ""];
}
} Signing-In / Using JWTYou can then easily sign-in to your app with the signIn("strapi", { username: "username", password: "password" }); You can then use the JWT by accessing the profile, as long as it's returned from the Hope this helps! |
Beta Was this translation helpful? Give feedback.
Hi there! Thank you for opening this discussion page, I haven't personally used or setup a Strapi CMS backend with authentication myself yet, but it's something I will consider creating an example for this project when I get around to it. In any case, SK-auth is customizable and well-equipped to handle all sorts of authentication flows, so Strapi's standard JWT implementation shouldn't be an issue.
I gave the documentation a look on the auth setup, and it looks like Strapi has a pretty simple login/auth flow. So my proposal would be to create the following provider in SK-auth and then just storing the JWT in the SK session so you can retrieve it from the frontend/client and use it to make…