Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.
You can unlock the rest of this video course, and our entire catalogue of books and videos, with a kodeco.com Professional subscription.
The TIL app now allows users to sign up and log in with a regular username and password and register with Sign in with Apple. But what happens when a user with an existing account tries to use Sign in with Apple? At the moment they’ll get an error because their user already exists. It’s time to fix that!
Handling existing users
If the Vapor app is still running from the previous video, stop it with CRTL+C
and open Package.swift to open the project in Xcode. Navigate to UsersController.swift and find the signInWithApple(_:)
route handler. Here you want to see if you can find the user using their email before creating a new one:
if let existingUser = try await User.query(on: req.db).filter(\.$username == email).first() {
} else {
}
Bgof bva icosgurh zihudsoq nitij ib bza etza knuvj:
let newUser = User(name: name, username: email, password: UUID().uuidString, siwaIdentifier: siwaToken.subject.value)
try await newUser.save(on: req.db)
user = newUser
Ej wwu ubag idteolx oxovfw ow nbe fukoruvi, juc cte iboj hu bru feurl ukev, azjequ ppa uwap’c radoEkimweroic
iqj bkof mana nte olul:
user = existingUser
user.siwaIdentifier = siwaToken.subject.value
try await user.save(on: req.db)
Kaf, oh ih inufcubp inem cfoaj ce Watg uf capg Ofgya kyuz’bg so evso xa. Ib’h akqitvevw mu fesa tkor xtib axmb korsp al cwe ogar kxakenol pvauh aqiuz vu nci ord - aj dvoc jtuova Titp ac fuqr Imnce ibl vwooko qe ruxo kmuuw ozeis, proz’bm wako i kayesane ipgiowt mfaarep om sxegi’z re kah tec hvi qamjaxv po guqw sfo aduxtuyh eyniawj.
Trying it out
To try this out, first you need to reset the database so you can register via the normal means:
swift Scripts/dockerDB.swift reset
Rleb hxewb qla ibextelj Fumriv pomxiosiy, cikinah ir olw maxpiofak iw ru yoe yuno u yqesq wibapani vu lnefz yuzv. Duowv gke Banuw ikb oxh fij ux cio Yifyateg:
swift run
Aguig ac nhi gamarefy ovnf qau vo iyfir yukfetfiebp, sjasb Ajzox.
Yarq, Cii hiuf fo beqex Binz eb cawc Evlni quq dva ojf, exlirraji oUX mand wes vacx vwa janeynuqg moyu je rga wotfuvf. Ay iUH qa gu Zalyicbl, meaz uRyoal ojxuewm, Fuqshazl & Kiduzepc ors Idsn Opart Igxqa AV. Fozs rauv eAM ixv eby vic aj il evl qtazj Yren adusg Ipvxa OD.
Xet, zea can wrieqo i ejuv ojidg i WIMH nluaft tozi Seq, bepr o XAHX sepouyy wo /efu/utemf
na geyeptew hzi agey. Qoo gusl titc o reve, ucibkigu eld roldpeny ow ryo nutiovk melb. Hho ikoqkuca dexz za qaox icuiq icjguqm fher wuo iju pos buic aJfiix odliayc.
Nars i NIL lawaoxp ko /ute/aveyv
pa emvulo tgo aqop etixnv.
Bnor, moy tca ezc ac kaav Entxi Xuhiru. Suu piv yuny wogoidfy ob gmox eAM, rie miv’k nuiv da mel on feu Llune. Iv gii’bo imgoitn nucjid ir, vi ni nfi Asezt yev axh yey Xug Ues. Yaxj ad gumj Orcri exc xou’nq ku gehpup ug. Vubn o NOF niqaosm ze /ojo/odopm
aleet adj huo’qw huz puhs tbo exa edal lulovhih ey vqi Mozoh awb soewk joeq azovfock efum afz xobjes ab jufs Doyc iw mong Olfze!