diff --git a/curriculum/challenges/english/06-quality-assurance/advanced-node-and-express/implementation-of-social-authentication.md b/curriculum/challenges/english/06-quality-assurance/advanced-node-and-express/implementation-of-social-authentication.md index 2912bbed16..58fd37d68d 100644 --- a/curriculum/challenges/english/06-quality-assurance/advanced-node-and-express/implementation-of-social-authentication.md +++ b/curriculum/challenges/english/06-quality-assurance/advanced-node-and-express/implementation-of-social-authentication.md @@ -35,40 +35,66 @@ Submit your page when you think you've got it right. If you're running into erro # --hints-- -Route /auth/github should be correct. +Route `/auth/github` should be correct. ```js -(getUserInput) => - $.get(getUserInput('url') + '/_api/routes.js').then( - (data) => { +async (getUserInput) => { + try { + const res = await fetch(getUserInput('url') + '/_api/routes.js'); + if (res.ok) { + const data = await res.text(); assert.match( - data.replace(/\s/g, ''), - /('|")\/auth\/github\/?\1[^]*?get.*?passport.authenticate.*?github/gi, - 'Route auth/github should only call passport.authenticate with github' - ); - }, - (xhr) => { - throw new Error(xhr.statusText); + data.replace(/\s/g, ''), + /passport.authenticate.*?github/g, + 'Route auth/github should only call passport.authenticate with github' + ); + } else { + throw new Error(res.statusText); } - ); + const res2 = await fetch(getUserInput('url') + '/_api/app-stack'); + if (res2.ok) { + const data2 = JSON.parse(await res2.json()); + const dataLayer = data2.find(layer => layer?.route?.path === '/auth/github'); + assert.deepInclude(dataLayer?.route, { methods: {get: true}, path: "/auth/github"}); + assert.deepInclude(dataLayer?.route?.stack?.[0], {method: "get", name: "authenticate"}); + } else { + throw new Error(res2.statusText); + } + } catch (err) { + throw new Error(err); + } +} ``` -Route /auth/github/callback should be correct. +Route `/auth/github/callback` should be correct. ```js -(getUserInput) => - $.get(getUserInput('url') + '/_api/routes.js').then( - (data) => { +async (getUserInput) => { + try { + const res = await fetch(getUserInput('url') + '/_api/routes.js'); + if (res.ok) { + const data = await res.text(); assert.match( data.replace(/\s/g, ''), - /('|")\/auth\/github\/callback\/?\1[^]*?get.*?passport.authenticate.*?github.*?failureRedirect:("|')\/\2/gi, + /failureRedirect:("|')\/\1/g, 'Route auth/github/callback should accept a get request and call passport.authenticate for github with a failure redirect to home' ); - }, - (xhr) => { - throw new Error(xhr.statusText); + } else { + throw new Error(res.statusText); } - ); + const res2 = await fetch(getUserInput('url') + '/_api/app-stack'); + if (res2.ok) { + const data2 = JSON.parse(await res2.json()); + const dataLayer = data2.find(layer => layer?.route?.path === '/auth/github/callback'); + assert.deepInclude(dataLayer?.route, { methods: {get: true}, path: "/auth/github/callback"}); + assert.deepInclude(dataLayer?.route?.stack?.[0], {method: "get", name: "authenticate"}); + } else { + throw new Error(res2.statusText); + } + } catch (err) { + throw new Error(err); + } +} ``` # --solutions--