-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add route to return the rectification config value
- Loading branch information
1 parent
6f85bfb
commit 2ec80ba
Showing
4 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
export async function getEmailRetificationConfig( | ||
ctx: Context, | ||
next: () => Promise<any> | ||
) { | ||
try { | ||
const userStoreToken = ctx.vtex.storeUserAuthToken?.split('.')[1] ?? '' | ||
|
||
const { account } = JSON.parse( | ||
Buffer.from(userStoreToken, 'base64').toString() | ||
) | ||
|
||
if (account !== ctx.vtex.account) { | ||
setForbiddenStatus(ctx) | ||
|
||
return | ||
} | ||
} catch (e) { | ||
setForbiddenStatus(ctx) | ||
|
||
return | ||
} | ||
|
||
//@ts-ignore | ||
Check failure on line 23 in node/routes/index.ts
|
||
ctx.status = 200 | ||
//@ts-ignore | ||
Check failure on line 25 in node/routes/index.ts
|
||
ctx.body = await ctx.clients.oms.getRmailRetificationConfig() | ||
|
||
await next() | ||
} | ||
|
||
function setForbiddenStatus(ctx: Context) { | ||
//@ts-ignore | ||
Check failure on line 32 in node/routes/index.ts
|
||
ctx.status = 403 | ||
//@ts-ignore | ||
Check failure on line 34 in node/routes/index.ts
|
||
ctx.body = 'Forbidden' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters