K
Kinde•11mo ago
andiputraw

Server Side authentication

Hello, i have a bit problem using kinde i probably just too dumb to understand how kinde work in general. TLDR: how to check the user logged in using authrozation code flow using typescript SDK. for the tech stack i am using deno fresh https://fresh.deno.dev . with typescript SDK so based on this https://kinde.com/docs/developer-tools/typescript-sdk/ and https://kinde.com/docs/developer-tools/using-kinde-without-an-sdk/#supported-grant-types-for-getting-access-tokens . it is said that if the page is rendered by server, it is better to use Authorization Code Flow. and that is what i do here. to make the server stateless. i am putting the session based on encrpted cookie.
class KindeSession implements SessionManager {
session: Session<string, string>;
constructor(ctx: FreshContext) {
this.session = ctx.state.session as Session<string, string>;
}
async getSessionItem(key: string) {
const data = this.session.get(key);
console.log("Getting data ", key, " ", data);
return data;
}
async setSessionItem(key: string, value: unknown) {
console.log(`Settting Session ${key} ${value}`);
this.session.set(key, value as string);
}
async removeSessionItem(key: string) {
console.log(`Removing Session ${key} `);
this.session.delete(key);
}
async destroySession() {
this.session.destroy();
}
}
class KindeSession implements SessionManager {
session: Session<string, string>;
constructor(ctx: FreshContext) {
this.session = ctx.state.session as Session<string, string>;
}
async getSessionItem(key: string) {
const data = this.session.get(key);
console.log("Getting data ", key, " ", data);
return data;
}
async setSessionItem(key: string, value: unknown) {
console.log(`Settting Session ${key} ${value}`);
this.session.set(key, value as string);
}
async removeSessionItem(key: string) {
console.log(`Removing Session ${key} `);
this.session.delete(key);
}
async destroySession() {
this.session.destroy();
}
}
however, based on https://kinde.com/docs/developer-tools/typescript-sdk/#check-if-user-is-authenticated. client.isAuthenticated(sessionManager) is only available on PKCE flow. so then, how can i know if the user is authenticated or not, as far as i know, after login() is invoked, it tried to set ac-set-key or acwpf-state-key if using PKCE flow to the session. and isAuthenticated() expect access_token to available in the session. which is i think is not related at all.
Kinde Docs
TypeScript SDK - Developer tools - Help center
Our developer tools provide everything you need to get started with Kinde.
Kinde Docs
Using Kinde without an SDK - Developer tools - Help center
Our developer tools provide everything you need to get started with Kinde.
5 Replies
Daniel_Kinde
Daniel_Kinde•11mo ago
Hi, The isAuthenticated is available on both the PKCE and authentication code flows. So this should work for you, are you having problems with it?
MaDsEn
MaDsEn•11mo ago
Have you checked https://github.com/kinde-starter-kits/deno-starter-kit. Pretty easy to change it to your specific needs. I am also using fresh.deno and got i working perfectly. Currently working on a better middleware option, but the package is a great starting point.
andiputraw
andiputrawOP•11mo ago
sorry but. that page does not exists on my side
No description
MaDsEn
MaDsEn•11mo ago
Sorry, it is still in private by the Kinde team. Got early access to it to test it out. Sended you a friend invite. I can send you the repo to clone 😉
andiputraw
andiputrawOP•11mo ago
good idea, already accepted your friend request. after seeing the template i think i know why it is not working before. the callback url should call this method await kindeClient.handleRedirectToApp() pardon for not reading the docs properly
Want results from more Discord servers?
Add your server