Peteswah
Peteswah
KKinde
Created by agr on 10/28/2024 in #💻┃support
getIdToken error
Thanks for raising this, I'll see if I can recreate it - this seems like a bug
24 replies
KKinde
Created by Rasel Hossain on 10/22/2024 in #💻┃support
I redirect to the login page after my access token expires.
Hey @Rasel Hossain , I thought the KindeProvider might be the solution to your problem, but it looks like a refresh is necessary to get the refreshToken to work properly. This is an issue we're looking to address asap - then hopefully we can get the token refreshing in the background
22 replies
KKinde
Created by Rasel Hossain on 10/22/2024 in #💻┃support
I redirect to the login page after my access token expires.
Hey @Rasel Hossain , I haven't used TRPC before, but it looks like what you are doing there is correct. refreshing the tokens in the background should be happening when you call isAuthenticated from the TRPCContext. The reason it may be redirecting to Kinde login could be middleware. Are you using Kinde middleware?
22 replies
KKinde
Created by Rasel Hossain on 10/22/2024 in #💻┃support
I redirect to the login page after my access token expires.
This should refresh tokens in he background
22 replies
KKinde
Created by Rasel Hossain on 10/22/2024 in #💻┃support
I redirect to the login page after my access token expires.
Hey @Rasel Hossain, would you be able to try wrapping your app in a Kinde Provider?
// AuthProvider.tsx
'use client';
import {KindeProvider} from '@kinde-oss/kinde-auth-nextjs';

export const AuthProvider = ({children}) => {
return <KindeProvider>{children}</KindeProvider>;
};
// AuthProvider.tsx
'use client';
import {KindeProvider} from '@kinde-oss/kinde-auth-nextjs';

export const AuthProvider = ({children}) => {
return <KindeProvider>{children}</KindeProvider>;
};
// layout.tsx
...
import {AuthProvider} from './AuthProvider';

export const metadata = {
title: 'Kinde Auth',
description: 'Kinde with NextJS App Router'
};

export default async function RootLayout({
children
}: {
children: React.ReactNode;
}) {
return (
<AuthProvider>
<html lang="en">
// Your app code here
</html>
</AuthProvider>
);
}
// layout.tsx
...
import {AuthProvider} from './AuthProvider';

export const metadata = {
title: 'Kinde Auth',
description: 'Kinde with NextJS App Router'
};

export default async function RootLayout({
children
}: {
children: React.ReactNode;
}) {
return (
<AuthProvider>
<html lang="en">
// Your app code here
</html>
</AuthProvider>
);
}
22 replies
KKinde
Created by Abel Trần on 10/6/2024 in #💻┃support
Issue with getKindeServerSession().refreshTokens(); in Next.js App Router
To see the updated user data, it will work automatically if you grab them from getKindeServerSession, but will need to force a reload (window.location.reload) for browserclient
25 replies
KKinde
Created by Abel Trần on 10/6/2024 in #💻┃support
Issue with getKindeServerSession().refreshTokens(); in Next.js App Router
with the API
25 replies
KKinde
Created by Abel Trần on 10/6/2024 in #💻┃support
Issue with getKindeServerSession().refreshTokens(); in Next.js App Router
^ this is how to use refreshtoken in the server action to get the user to update
25 replies
KKinde
Created by Abel Trần on 10/6/2024 in #💻┃support
Issue with getKindeServerSession().refreshTokens(); in Next.js App Router
'use client';

import {useKindeBrowserClient} from '@kinde-oss/kinde-auth-nextjs';
import {updateUserName} from '../../actions/kinde';

export const PersonData = () => {
const {user} = useKindeBrowserClient();
const handleSubmit = async (formData: FormData) => {
const givenName = formData.get('givenName') as string;
await updateUserName({userId: user.id, userName: givenName});
// window.location.reload(); (if using browser client)
};
return (
<div>
<form action={handleSubmit}>
<label htmlFor="orgName">Organization Name:</label>
<input
type="text"
id="givenName"
name="givenName"
defaultValue={user?.given_name}
/>
<button type="submit">Update user first name</button>
</form>
<pre>{JSON.stringify(user, null, 2)}</pre>;
</div>
);
};
'use client';

import {useKindeBrowserClient} from '@kinde-oss/kinde-auth-nextjs';
import {updateUserName} from '../../actions/kinde';

export const PersonData = () => {
const {user} = useKindeBrowserClient();
const handleSubmit = async (formData: FormData) => {
const givenName = formData.get('givenName') as string;
await updateUserName({userId: user.id, userName: givenName});
// window.location.reload(); (if using browser client)
};
return (
<div>
<form action={handleSubmit}>
<label htmlFor="orgName">Organization Name:</label>
<input
type="text"
id="givenName"
name="givenName"
defaultValue={user?.given_name}
/>
<button type="submit">Update user first name</button>
</form>
<pre>{JSON.stringify(user, null, 2)}</pre>;
</div>
);
};
export const updateUserName = async (props: {
userId: string;
userName: string;
}) => {
init();
await Users.updateUser({
id: props.userId,
requestBody: {
given_name: props.userName
}
});

await getKindeServerSession().refreshTokens();
revalidatePath('/dashboard', 'page');
};
export const updateUserName = async (props: {
userId: string;
userName: string;
}) => {
init();
await Users.updateUser({
id: props.userId,
requestBody: {
given_name: props.userName
}
});

await getKindeServerSession().refreshTokens();
revalidatePath('/dashboard', 'page');
};
25 replies
KKinde
Created by Abel Trần on 10/6/2024 in #💻┃support
Issue with getKindeServerSession().refreshTokens(); in Next.js App Router
I will try and recreate the server action experience you are having today
25 replies
KKinde
Created by Abel Trần on 10/6/2024 in #💻┃support
Issue with getKindeServerSession().refreshTokens(); in Next.js App Router
Hey Abel what is the behaviour you're expecting on your app when data is updated on the Kinde dashboard?
25 replies
KKinde
Created by fxaxiom on 9/14/2024 in #💻┃support
Redirection without <RegisterLink>
hey @fxaxiom you can redirect to /api/auth/register
13 replies
KKinde
Created by Kenton on 8/27/2024 in #💻┃support
Kinde Management API - 400 Bad Request: malformed Host header
hey @Kenton - the purpose of refreshTokens is to sync up the the tokens stored in the cookies with Kinde data. So if Kinde data is updated via the api, data will be changed on Kinde, but it wont be reflected in the tokens (in your app) unless you refreshTokens. Hope that made sense!
15 replies
KKinde
Created by Kenton on 8/27/2024 in #💻┃support
Kinde Management API - 400 Bad Request: malformed Host header
Although you may want to have it inside the trycatch 😄
15 replies
KKinde
Created by Kenton on 8/27/2024 in #💻┃support
Kinde Management API - 400 Bad Request: malformed Host header
Something like:
import {NextRequest, NextResponse} from "next/server";
import {Organizations, init} from "@kinde/management-api-js";

export async function POST(req: NextRequest) {
const {refreshTokens} = getKindeServerSession()
try {
init();

const orgResponse = await Organizations.createOrganization({
requestBody: {
name: "test-org",
handle: "test-org",
},
});

const orgCode = orgResponse.organization?.code;
const userId = "hard_coded_user_id"
if (orgCode && userId) {
const response = await Organizations.addOrganizationUsers({
orgCode: orgCode,
requestBody: {
users: [{ id: userId }],
},
});
console.log("User added successfully:", response);
} else {
console.error("Invalid orgCode or user ID");
}
} catch (error) {
console.error("Error creating organization or adding user:", error);
}
await refreshTokens();
return NextResponse.json({});
}
import {NextRequest, NextResponse} from "next/server";
import {Organizations, init} from "@kinde/management-api-js";

export async function POST(req: NextRequest) {
const {refreshTokens} = getKindeServerSession()
try {
init();

const orgResponse = await Organizations.createOrganization({
requestBody: {
name: "test-org",
handle: "test-org",
},
});

const orgCode = orgResponse.organization?.code;
const userId = "hard_coded_user_id"
if (orgCode && userId) {
const response = await Organizations.addOrganizationUsers({
orgCode: orgCode,
requestBody: {
users: [{ id: userId }],
},
});
console.log("User added successfully:", response);
} else {
console.error("Invalid orgCode or user ID");
}
} catch (error) {
console.error("Error creating organization or adding user:", error);
}
await refreshTokens();
return NextResponse.json({});
}
15 replies
KKinde
Created by Kenton on 8/27/2024 in #💻┃support
Kinde Management API - 400 Bad Request: malformed Host header
yup! I think what we want here is to call refreshTokens() from getKindeServerSession before returning the NextResponse
15 replies
KKinde
Created by Yvens on 4/22/2024 in #💻┃support
What would be the most secure way to create invitation link for users to join an organizations ?
^ That is a great idea
5 replies
KKinde
Created by dillorscroft on 8/13/2024 in #💻┃support
Custom Properties
The getUser function will return a user with the custom properties as long as they are in the token. You will have to define which custom properties you have to get the TS autocomplete to work. So const user = await getUser<{myCustomProp: string}>().
{
id: ...,
first_name: ...,
...,
properties: {
...,
myCustomProp: "hello world"
}
}
{
id: ...,
first_name: ...,
...,
properties: {
...,
myCustomProp: "hello world"
}
}
14 replies
KKinde
Created by dillorscroft on 8/13/2024 in #💻┃support
Custom Properties
Hey guys, there is a PR waiting to get merged with the changes
14 replies
KKinde
Created by DavidF9265 on 8/17/2024 in #💻┃support
Post logout url in NextjsSDK not redirecting
Also if I could get confirmation that the allowed logout redirect URLs are for the correct Application, that would be helpful info to help us debug
19 replies