mnewcomer
mnewcomer
KKinde
Created by mnewcomer on 12/6/2023 in #💻┃support
NextJS App Router v2 getAccessToken() and getToken()
Holy shit @peteswah, thank you so much
7 replies
KKinde
Created by mnewcomer on 12/6/2023 in #💻┃support
NextJS App Router v2 getAccessToken() and getToken()
No description
7 replies
KKinde
Created by mnewcomer on 12/6/2023 in #💻┃support
NextJS App Router v2 getAccessToken() and getToken()
Just upgraded to v2.0.12 from v2.0.11. Here's some more context:
"use client"

export const ClientProvider: React.FC<ClientProviderProps> = ({ children }) => {
const { getToken, getAccessToken, accessToken, user } =
useKindeBrowserClient()
// const { getToken, getAccessToken, accessToken, user } = useKindeAuth() // tried with both of useKindeAuth() + useKindeBrowserClient()
console.log(getAccessToken())
console.log(getToken())
console.log(accessToken)
console.log(user)

// ...
}
"use client"

export const ClientProvider: React.FC<ClientProviderProps> = ({ children }) => {
const { getToken, getAccessToken, accessToken, user } =
useKindeBrowserClient()
// const { getToken, getAccessToken, accessToken, user } = useKindeAuth() // tried with both of useKindeAuth() + useKindeBrowserClient()
console.log(getAccessToken())
console.log(getToken())
console.log(accessToken)
console.log(user)

// ...
}
This outputs (the "/" route is wrapped with this <ClientProvider/> wrapper):
Next.js 14.0.3 (turbo)
- Local: http://localhost:3000
- Environments: .env.local

Ready in 590ms
Compiling /page ...
Compiled /page in 5.6s
null
null
null
null
Next.js 14.0.3 (turbo)
- Local: http://localhost:3000
- Environments: .env.local

Ready in 590ms
Compiling /page ...
Compiled /page in 5.6s
null
null
null
null
^^ i am logged in here, my user information is available through the code below... On the server side of that route (which has all been working):
// app/(locked)/layout.tsx
const { isAuthenticated, getUser, getPermission, getAccessToken, getIdToken } =
getKindeServerSession()

export default async function LockedLayout({
children,
}: {
children: React.ReactNode
}) {
if (!(await isAuthenticated())) {
// correctly redirects, would love to move this to something else but it works
redirect("/login")
}
const perm = await getPermission("admin") // want to move this to the ClientProvider wrapper
const user = await getUser() // want to move this to the ClientProvider wrapper
const admin = perm?.isGranted || false

return (
<ClientProvider>
// ...
</ClientProvider>

// ...
}
// app/(locked)/layout.tsx
const { isAuthenticated, getUser, getPermission, getAccessToken, getIdToken } =
getKindeServerSession()

export default async function LockedLayout({
children,
}: {
children: React.ReactNode
}) {
if (!(await isAuthenticated())) {
// correctly redirects, would love to move this to something else but it works
redirect("/login")
}
const perm = await getPermission("admin") // want to move this to the ClientProvider wrapper
const user = await getUser() // want to move this to the ClientProvider wrapper
const admin = perm?.isGranted || false

return (
<ClientProvider>
// ...
</ClientProvider>

// ...
}
Which get's the user, isAuthenticated() and admin perm correctly
7 replies
KKinde
Created by mnewcomer on 11/22/2023 in #💻┃support
Session Storage Cleared before Callback
@Oli - Kinde Super super useful information. I'll check out those NextJS docs and try to get something similar working with Astro. Also pretty new to Astro so should be a great opportunity to learn about their state management. Thank you so much for putting in the time to get back to me. Hope you have a great rest of your day.
5 replies
KKinde
Created by mnewcomer on 11/22/2023 in #💻┃support
Session Storage Cleared before Callback
For some further context. After the Session Storage get's cleared out, my Browser Cookies get populated with enduser_session_id and kbtc keys with domain set to .auth.xxxx.com. These cookies disappear on redirect/refresh but not navigation.... which might suggest some sort of state issue with how I have astro set up?? I don't have the expertise to say for sure.
Something that is a little odd is that when I handleLogin after already being authenticated, Kinde doesn't force me to log back in: implying that my tokens are stored successfully somewhere, but I can't find where. Still issue persits of once logged in. Expected isAuthenticated() -> true but it returns false...
5 replies