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/website/libs/auth.ts

51 lines
1.3 KiB

import axios from 'axios';
import {signIn} from "next-auth/react";
import * as _ from 'lodash';
import {config} from "../config";
import {environment} from "../environments/environment";
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(`${environment.strapiApiUrl}/auth/local`, {
identifier: email,
password,
});
if (res && res.data) {
const user = await axios.get(`${environment.strapiApiUrl}/users/${res.data.user.id}?populate=deep`);
if (user && user.data) {
res.data.user = {...res.data.user, ...user.data};
}
}
return res.data;
}
export async function lostPasswordStrapi({email}) {
const res = await axios.post(`${environment.strapiApiUrl}/auth/forgot-password`, {email});
if (res && res.data) {
return res.data.ok;
} else {
return false;
}
}
export async function resetPasswordStrapi({password, passwordConfirmation, code}) {
const res = await axios.post(`${environment.strapiApiUrl}/auth/reset-password`, {
password,
passwordConfirmation,
code
});
if (res && res.data) {
return !_.isNil(res.data.jwt);
} else {
return false;
}
}