Nocteln
Nocteln
Explore posts from servers
NNuxt
Created by Nocteln on 4/28/2024 in #❓・help
access to something everywhere in the project
No description
5 replies
NNuxt
Created by Nocteln on 4/28/2024 in #❓・help
access to something everywhere in the project
I'm trying to fetch data from my api but I got many errors . Can You help me please Here is my code :
// composables/user.ts
export const useUser = async () => {
const tempUser = useAuth();
let user;
try {
const { data } = await useFetch(`/api/auth/${tempUser.user?.id}`, {
method: "POST",
body: {
user: tempUser.user,
},
headers: {
"Content-Type": "application/json",
},
});
user = data.value;
} catch (e) {
console.log(e);
}
return useState("foo", () => "cc");
};
// composables/user.ts
export const useUser = async () => {
const tempUser = useAuth();
let user;
try {
const { data } = await useFetch(`/api/auth/${tempUser.user?.id}`, {
method: "POST",
body: {
user: tempUser.user,
},
headers: {
"Content-Type": "application/json",
},
});
user = data.value;
} catch (e) {
console.log(e);
}
return useState("foo", () => "cc");
};
// /api/users/[user].post.ts
import { prisma } from "../../../prisma/db";

export default defineEventHandler(async (event) => {
console.log("cc");
const { user: userInfo } = await readBody(event);

if (!userInfo)
return "error while fetching user : not user found ([user].post.ts]";
let { email, id, name, picture, given_name } = userInfo;
let newUser;

if (picture === "" || picture === null)
picture =
"https://imebehavioralhealth.com/wp-content/uploads/2021/10/user-icon-placeholder-1.png";

try {
const user = await prisma.user.findMany({
where: {
kindeId: userInfo.id,
},
});

if (user.length > 0) {
return {
user: user[0],
};
} else {
newUser = await prisma.user.create({
data: {
email,
kindeId: id,
name,
profilePicture: picture,
pseudo: given_name,
},
});
}

return {
user: newUser,
};
} catch (error) {
console.error(error);
}
});
// /api/users/[user].post.ts
import { prisma } from "../../../prisma/db";

export default defineEventHandler(async (event) => {
console.log("cc");
const { user: userInfo } = await readBody(event);

if (!userInfo)
return "error while fetching user : not user found ([user].post.ts]";
let { email, id, name, picture, given_name } = userInfo;
let newUser;

if (picture === "" || picture === null)
picture =
"https://imebehavioralhealth.com/wp-content/uploads/2021/10/user-icon-placeholder-1.png";

try {
const user = await prisma.user.findMany({
where: {
kindeId: userInfo.id,
},
});

if (user.length > 0) {
return {
user: user[0],
};
} else {
newUser = await prisma.user.create({
data: {
email,
kindeId: id,
name,
profilePicture: picture,
pseudo: given_name,
},
});
}

return {
user: newUser,
};
} catch (error) {
console.error(error);
}
});
5 replies
NNuxt
Created by Nocteln on 4/28/2024 in #❓・help
access to something everywhere in the project
ok thank you
5 replies
KKinde
Created by Nocteln on 4/20/2024 in #💻┃support
add user in mongodb database on nuxt
ok thx
23 replies
KKinde
Created by Nocteln on 4/20/2024 in #💻┃support
add user in mongodb database on nuxt
i cant use the webhook on localhost?
23 replies
KKinde
Created by Nocteln on 4/20/2024 in #💻┃support
add user in mongodb database on nuxt
okay thank you
23 replies
KKinde
Created by Nocteln on 4/20/2024 in #💻┃support
add user in mongodb database on nuxt
its nocteln.kinde.com
23 replies
KKinde
Created by Nocteln on 4/20/2024 in #💻┃support
add user in mongodb database on nuxt
oh ok
23 replies
KKinde
Created by Nocteln on 4/20/2024 in #💻┃support
add user in mongodb database on nuxt
No description
23 replies
KKinde
Created by Nocteln on 4/20/2024 in #💻┃support
add user in mongodb database on nuxt
No description
23 replies
KKinde
Created by Nocteln on 4/20/2024 in #💻┃support
add user in mongodb database on nuxt
No description
23 replies
KKinde
Created by Nocteln on 4/20/2024 in #💻┃support
add user in mongodb database on nuxt
Hey, thank you I think my business name is "habit tracker" or something like that I already posted a request on the website to get access to it
23 replies
KKinde
Created by Nocteln on 4/20/2024 in #💻┃support
add user in mongodb database on nuxt
Ok thx
23 replies
KKinde
Created by Nocteln on 4/20/2024 in #💻┃support
add user in mongodb database on nuxt
Thanks but when do I call the function?
23 replies
KKinde
Created by Nocteln on 4/20/2024 in #💻┃support
add user in mongodb database on nuxt
Yes
23 replies