mnewcomer
mnewcomer
KKinde
Created by mnewcomer on 12/6/2023 in #💻┃support
NextJS App Router v2 getAccessToken() and getToken()
Hello again! Loving Kinde (and can't wait for custom favicons....), but I've ran into a little bit of a desync between either my implementation or the kinde documentation. I have a backend that I want to send the user's JWT to. I figured I would use the serverside method getAccessToken(), but it 1) returns null on a logged in user (profile pic, name, email from getUser() went fine, and 2) even if I got the KindeAccessToken there are no methods to convert it to a JWT (althought the documentation suggests getAccessToken() -> Promise<string>. So, I was like, that's okay, I'll add the token on the client side api client with the kinde client methods from useKindeAuth, getToken seems to return string | null but I only get null still. Wondering why I can't seem to access the JWT even if it's stored in Application Cookies. Would love any help, very excited to finally get this integrated with the backend. P.S. other than this token stuff I love the next app router sdk. it's been super easy to use and has sped up my development enormously.
7 replies
KKinde
Created by mnewcomer on 11/22/2023 in #💻┃support
Session Storage Cleared before Callback
Kinde SDK: TS, Version: ^2.3.0, Framework: Astro w/ React (shadcn ui) Hello, first of all, love the idea behind kinde and really want to get this working. A quick preface: I am mainly a backend developer trying to get a front-end up and going. I don't have a bunch of experience with js, ts, and the ever evolving front-end ecosystem. I added all the functions I needed to a src/kinde/client.ts + for different routes i use the methods defined in a <script> tag (I can eventually just setup api routes, but this is just easier for me now, maybe this the issue??). My login route /auth/login is basically just this (i really don't know if this is stupid, maybe it is lol)
<script>
import { handleLogin } from "@/kinde/client"
handleLogin()
</script>
<script>
import { handleLogin } from "@/kinde/client"
handleLogin()
</script>
and my callback route /auth/callback looks like this:
// src/pages/auth/callback.astro
<script>
import { handleRedirect } from "@/kinde/client"
handleRedirect()
</script>
// src/pages/auth/callback.astro
<script>
import { handleRedirect } from "@/kinde/client"
handleRedirect()
</script>
And my client looks like this:
// src/kinde/client.ts
export const kindeClient = createKindeBrowserClient({
authDomain: "xxxx",
clientId: "xxxxx",
logoutRedirectURL: "xxxx",
redirectURL: "http://localhost:4321/auth/callback",
})

// ... other funcs

export async function handleLogin() {
const url = await kindeClient.login()
// Redirect
window.location.href = url.toString()
}
// src/kinde/client.ts
export const kindeClient = createKindeBrowserClient({
authDomain: "xxxx",
clientId: "xxxxx",
logoutRedirectURL: "xxxx",
redirectURL: "http://localhost:4321/auth/callback",
})

// ... other funcs

export async function handleLogin() {
const url = await kindeClient.login()
// Redirect
window.location.href = url.toString()
}
Looking at the Session Storage a KV pair gets populated and disappears right during/after the /auth/callback redirect from a successful Kinde login. Further attempts to call kindeClient.isAuthenticated() return false (obviously nothing in storage, just confirming it didn't work) Anyone think they could help me figure this out? Really excited to get this just up so I can focus on the actual app/service itself... and so i can get out of front-end hell and back to back-end bliss 😉 Love the product, look forward to getting this working. Very excited to try M2M auth next. Best, Max
5 replies