local g=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local n=require(script.Parent.Parent.Parent.Promise)local K=require(script.Auth)local f={}local k={}k.__index=k function f.new(g)local n={}n.App=g return setmetatable(n,k)end function k.SignInWithEmailAndPassword(k,g,f)return n.new(function(n,L)local A=k.App local F,s=(A._http:POST("\073\100\101\110\116\105\116\121\084\111\111\108\075\105\116","\058\115\105\103\110\073\110\087\105\116\104\080\097\115\115\119\111\114\100",{key=A.APIKey},{email=g,password=f;returnSecureToken=true})):await()if F then n(K.new(A,{IdToken=s.idToken,ExpiresIn=s.expiresIn}))else L(s)end end)end return f
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Promise = require(script.Parent.Parent.Parent.Promise)
local Auth = require(script.Auth)

local Authentication = {}
local AUTHENTICATION_METATABLE = {}
AUTHENTICATION_METATABLE.__index = AUTHENTICATION_METATABLE

function Authentication.new(app)
    local self = {}

    self.App = app

    return setmetatable(self, AUTHENTICATION_METATABLE)
end

function AUTHENTICATION_METATABLE:SignInWithEmailAndPassword(email, password)
    return Promise.new(function(resolve, reject)
        local app = self.App

        local status, response = app._http:POST("IdentityToolKit", ":signInWithPassword", {
            key = app.APIKey,
        }, {
            email = email,
            password = password,
            returnSecureToken = true,
        }):await()

        if status then
            resolve(Auth.new(
                app,
                {
                    IdToken = response.idToken,
                    ExpiresIn = response.expiresIn,
                }
            ))
        else
            reject(response)
        end
    end)
end

return Authentication
