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)
},
edwinn1337
05/25/2022, 9:42 AMreturn ThirdPartyEmailPassword.emailPasswordSignIn(input.email, input.password)
not sure if i need to await, but doesnt work eitheredwinn1337
05/25/2022, 9:43 AMedwinn1337
05/25/2022, 9:43 AMnkshah2
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,
}),
],
edwinn1337
05/25/2022, 9:48 AMjs
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
nkshah2
05/25/2022, 9:51 AMThirdPartyEmailPassword.function
now points to your function. So returning ThirdPartyEmailPassword.emailPasswordSignIn
is just calling itself endlesslyedwinn1337
05/25/2022, 9:52 AMedwinn1337
05/25/2022, 9:52 AMedwinn1337
05/25/2022, 9:53 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 AMedwinn1337
05/25/2022, 10:11 AMjs
//check if there is a superTokensUser
const superTokensUser = await ThirdPartyEmailPassword.getUsersByEmail(input.email)
edwinn1337
05/25/2022, 10:11 AMoriginal
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 yoursnkshah2
05/25/2022, 10:13 AMoriginal
unless you intentionally want to call your version of a functionnkshah2
05/25/2022, 10:15 AMnkshah2
05/25/2022, 10:16 AMedwinn1337
05/25/2022, 12:52 PMedwinn1337
05/25/2022, 12:52 PMedwinn1337
05/25/2022, 12:52 PMedwinn1337
05/25/2022, 12:53 PMnkshah2
05/25/2022, 12:53 PMnkshah2
05/25/2022, 12:54 PMedwinn1337
05/25/2022, 12:54 PMedwinn1337
05/25/2022, 12:54 PMimport { Http, HttpOptions, HttpResponse } from '@capacitor-community/http'
edwinn1337
05/25/2022, 12:54 PMnkshah2
05/25/2022, 12:55 PMnkshah2
05/25/2022, 12:55 PMedwinn1337
05/25/2022, 12:55 PMedwinn1337
05/25/2022, 12:55 PMnkshah2
05/25/2022, 12:55 PM