You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nx-guitar-school/apps/client/libs/auth.ts

27 lines
655 B

import axios from 'axios';
import {signIn} from "next-auth/react";
const strapiUrl = process.env.STRAPI_URL_API;
export async function createJwtToken(email, password) {
return await signIn('credentials', {
redirect: false,
email,
password,
});
}
export async function signInStrapi({email, password}) {
const res = await axios.post(`${strapiUrl}/auth/local`, {
identifier: email,
password,
});
if (res && res.data) {
const user = await axios.get(`${strapiUrl}/users/${res.data.user.id}?populate=deep`);
if (user && user.data) {
res.data.user = {...res.data.user, ...user.data};
}
}
return res.data;
}