EdwinN1337
05/25/2022, 9:40 AMemailPasswordSignIn
can't figure out whynkshah2
05/25/2022, 9:41 AMEdwinN1337
05/25/2022, 9:41 AMjs
emailPasswordSignIn: async (input) => {
//TODO: add device-token logic
const validEmail = await validateEmail(input.email)
if (!validEmail) {
return {
status: 'WRONG_CREDENTIALS_ERROR',
}
}
//check if user is in db
const hasuraUser = await sdk.getUserByEmail({
email: input.email.toLowerCase().trim(),
})
if (hasuraUser.data?.customer.length === 0) {
return {
status: 'WRONG_CREDENTIALS_ERROR',
}
}
//check if there is a superTokensUser
const superTokensUser = await ThirdPartyEmailPassword.getUsersByEmail(input.email)
if (!superTokensUser) {
//check if password is valid and create superTokensUser
const valid = await bcrypt.compare(
input.password,
hasuraUser.data.customer[0].password,
)
if (!valid) {
return {
status: 'WRONG_CREDENTIALS_ERROR',
}
}
const signupResponse = await ThirdPartyEmailPassword.emailPasswordSignUp(
input.email,
input.password,
)
if (signupResponse.status !== 'OK') {
return {
status: 'WRONG_CREDENTIALS_ERROR',
}
}
}
return ThirdPartyEmailPassword.emailPasswordSignIn(input.email, input.password)
},
return ThirdPartyEmailPassword.emailPasswordSignIn(input.email, input.password)
not sure if i need to await, but doesnt work eithernkshah2
05/25/2022, 9:44 AMEdwinN1337
05/25/2022, 9:48 AMjs
export const backendConfig = (): TypeInput => {
return {
framework: 'express',
supertokens: {
// These are the connection details of the app you created on supertokens.com
connectionURI: process.env.SUPERTOKENS_CONNECTION_URI,
apiKey: process.env.SUPERTOKENS_API_KEY,
},
appInfo,
recipeList: [
ThirdPartyEmailPassword.init({
providers: [
Google({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
}),
],
js
export const appInfo = {
// learn more about this on https://supertokens.com/docs/emailpassword/appinfo
appName: 'Lokalist Webshop',
apiDomain: process.env.NEXT_PUBLIC_FRONTEND_URL,
websiteDomain: process.env.NEXT_PUBLIC_FRONTEND_URL,
apiBasePath: '/api/auth',
websiteBasePath: '/auth',
}
nkshah2
05/25/2022, 9:49 AMemailPasswordSignIn
function, the parent function should receive an object (named original
in the docs). When returning you should use original.emailPasswordSignIn
instead of ThirdPartyEmailPassword.emailPasswordSignIn
ThirdPartyEmailPassword.function
now points to your function. So returning ThirdPartyEmailPassword.emailPasswordSignIn
is just calling itself endlesslyEdwinN1337
05/25/2022, 9:52 AMnkshah2
05/25/2022, 9:53 AMEdwinN1337
05/25/2022, 9:53 AMreturn oI.emailPasswordSignIn(input)
😉nkshah2
05/25/2022, 9:53 AMEdwinN1337
05/25/2022, 10:11 AMjs
//check if there is a superTokensUser
const superTokensUser = await ThirdPartyEmailPassword.getUsersByEmail(input.email)
original
nkshah2
05/25/2022, 10:13 AMThirdParyEmailPassword.function
would call your version of the function (defaulting to the SDKs version if you dont override it). original.function
always calls the SDKs implementation and not yoursoriginal
unless you intentionally want to call your version of a functionEdwinN1337
05/25/2022, 12:52 PMnkshah2
05/25/2022, 12:53 PMEdwinN1337
05/25/2022, 12:54 PMimport { Http, HttpOptions, HttpResponse } from '@capacitor-community/http'
nkshah2
05/25/2022, 12:55 PMEdwinN1337
05/25/2022, 12:55 PMnkshah2
05/25/2022, 12:55 PM