This repository has been archived by the owner on Nov 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: package generateQRCode function
- Loading branch information
1 parent
575ecf1
commit cc50b7e
Showing
5 changed files
with
28 additions
and
4 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
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,7 @@ | ||
import { Field, ObjectType } from '@nestjs/graphql' | ||
|
||
@ObjectType() | ||
export class TOTPModel { | ||
@Field() | ||
public readonly qrcode: string | ||
} |
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 |
---|---|---|
@@ -1,4 +1,16 @@ | ||
import QRCode from 'qrcode' | ||
import { ApolloError } from 'apollo-server-express' | ||
|
||
export const generateSMSVerificationCode = () => | ||
(Math.floor(Math.random() * 10000) + 10000).toString().slice(1) | ||
|
||
export const jsonStringify = <T>(obj: T) => JSON.stringify(obj).replace(/"([^(")"]+)":/g, '$1:') | ||
|
||
export const generateQRCode = async (url: string) => { | ||
try { | ||
const qrcode = await QRCode.toDataURL(url) | ||
return { qrcode } | ||
} catch (err) { | ||
throw new ApolloError('Generate QR code failed!') | ||
} | ||
} |