This repository has been archived by the owner on May 7, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add refresh token senario on auth (#516)
* Add datatype to schema * Add refresh token senario on auth * Add [ErrorBoundary] and `getIdToken` in `fetchGraphql` * Impl `getIdToken` api
- Loading branch information
Showing
17 changed files
with
508 additions
and
42 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
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,45 @@ | ||
import * as Config from '../../config'; | ||
|
||
import AsyncStorage from '@react-native-async-storage/async-storage'; | ||
|
||
const {ROOT_URL} = Config; | ||
|
||
type Result = { | ||
token?: string; | ||
message?: string; | ||
}; | ||
|
||
export const getIdToken = async ( | ||
body?: Record<string, unknown>, | ||
signal?: AbortController['signal'], | ||
): Promise<string> => { | ||
const token = (await AsyncStorage.getItem('token')) || ''; | ||
|
||
if (!token) { | ||
return ''; | ||
} | ||
|
||
const fetchOption = { | ||
signal, | ||
method: 'POST', | ||
headers: { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
Authorization: token, | ||
}, | ||
body: JSON.stringify(body), | ||
}; | ||
|
||
try { | ||
const res: Response = await fetch(`${ROOT_URL}/get_id_token`, fetchOption); | ||
const json: Result = await res.json(); | ||
|
||
if (json.token && json.token !== token) { | ||
await AsyncStorage.setItem('token', token); | ||
} | ||
|
||
return json.token || ''; | ||
} catch (err: any) { | ||
throw new Error(err); | ||
} | ||
}; |
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,58 @@ | ||
import {Button, Typography} from 'dooboo-ui'; | ||
import {DevSettings, View} from 'react-native'; | ||
import React, {ReactElement, useEffect} from 'react'; | ||
|
||
import AsyncStorage from '@react-native-async-storage/async-storage'; | ||
import {getString} from '../../STRINGS'; | ||
import styled from '@emotion/native'; | ||
|
||
const Container = styled.SafeAreaView` | ||
margin: 0 24px; | ||
flex: 1; | ||
justify-content: center; | ||
`; | ||
|
||
export const handleError = (error: any, stack?: string): void => { | ||
if (__DEV__) { | ||
// eslint-disable-next-line no-console | ||
console.error(stack, error); | ||
} | ||
}; | ||
|
||
interface Props { | ||
error: Error; | ||
resetError: Function; | ||
} | ||
|
||
export default function FallbackComponent({resetError}: Props): ReactElement { | ||
useEffect(() => { | ||
AsyncStorage.removeItem('token'); | ||
AsyncStorage.removeItem('push_token'); | ||
|
||
resetError(); | ||
}, [resetError]); | ||
|
||
return ( | ||
<Container> | ||
<> | ||
<Typography.Heading1>{getString('ERROR_OCCURED')}</Typography.Heading1> | ||
</> | ||
<View style={{height: 32}} /> | ||
<Button | ||
size="large" | ||
onPress={() => resetError()} | ||
text={getString('TRY_AGAIN')} | ||
/> | ||
<View style={{height: 12}} /> | ||
{__DEV__ ? ( | ||
<Button | ||
style={{marginBottom: 32}} | ||
size="large" | ||
onPress={() => DevSettings.reload()} | ||
text={getString('RELOAD')} | ||
/> | ||
) : null} | ||
</Container> | ||
); | ||
} |
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
167 changes: 167 additions & 0 deletions
167
server/prisma/migrations/20211218094713_datatype_refresh_token/migration.sql
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,167 @@ | ||
/* | ||
Warnings: | ||
- You are about to alter the column `name` on the `Channel` table. The data in that column could be lost. The data in that column will be cast from `Text` to `VarChar(255)`. | ||
- You are about to alter the column `lastMessageId` on the `Channel` table. The data in that column could be lost. The data in that column will be cast from `Text` to `VarChar(255)`. | ||
- You are about to alter the column `token` on the `Notification` table. The data in that column could be lost. The data in that column will be cast from `Text` to `VarChar(1024)`. | ||
- You are about to alter the column `device` on the `Notification` table. The data in that column could be lost. The data in that column will be cast from `Text` to `VarChar(255)`. | ||
- You are about to alter the column `os` on the `Notification` table. The data in that column could be lost. The data in that column will be cast from `Text` to `VarChar(255)`. | ||
- You are about to alter the column `userId` on the `Notification` table. The data in that column could be lost. The data in that column will be cast from `Text` to `VarChar(255)`. | ||
- You are about to alter the column `socialId` on the `Profile` table. The data in that column could be lost. The data in that column will be cast from `Text` to `VarChar(255)`. | ||
- You are about to alter the column `value` on the `Reaction` table. The data in that column could be lost. The data in that column will be cast from `Text` to `VarChar(4)`. | ||
- You are about to alter the column `userId` on the `Reaction` table. The data in that column could be lost. The data in that column will be cast from `Text` to `VarChar(255)`. | ||
- You are about to alter the column `messageId` on the `Reaction` table. The data in that column could be lost. The data in that column will be cast from `Text` to `VarChar(255)`. | ||
- You are about to alter the column `senderId` on the `Reply` table. The data in that column could be lost. The data in that column will be cast from `Text` to `VarChar(255)`. | ||
- You are about to alter the column `messageId` on the `Reply` table. The data in that column could be lost. The data in that column will be cast from `Text` to `VarChar(255)`. | ||
- You are about to alter the column `password` on the `User` table. The data in that column could be lost. The data in that column will be cast from `Text` to `VarChar(255)`. | ||
- You are about to alter the column `name` on the `User` table. The data in that column could be lost. The data in that column will be cast from `Text` to `VarChar(255)`. | ||
- You are about to alter the column `nickname` on the `User` table. The data in that column could be lost. The data in that column will be cast from `Text` to `VarChar(255)`. | ||
- You are about to alter the column `thumbURL` on the `User` table. The data in that column could be lost. The data in that column will be cast from `Text` to `VarChar(1024)`. | ||
- You are about to alter the column `photoURL` on the `User` table. The data in that column could be lost. The data in that column will be cast from `Text` to `VarChar(1024)`. | ||
- You are about to alter the column `phone` on the `User` table. The data in that column could be lost. The data in that column will be cast from `Text` to `VarChar(255)`. | ||
*/ | ||
-- DropForeignKey | ||
ALTER TABLE "BlockedUser" DROP CONSTRAINT "BlockedUser_blockedUserId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "BlockedUser" DROP CONSTRAINT "BlockedUser_userId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "Friend" DROP CONSTRAINT "Friend_friendId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "Friend" DROP CONSTRAINT "Friend_userId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "Membership" DROP CONSTRAINT "Membership_channelId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "Membership" DROP CONSTRAINT "Membership_userId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "Message" DROP CONSTRAINT "Message_channelId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "Message" DROP CONSTRAINT "Message_senderId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "Notification" DROP CONSTRAINT "Notification_userId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "Profile" DROP CONSTRAINT "Profile_userId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "Reaction" DROP CONSTRAINT "Reaction_messageId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "Reaction" DROP CONSTRAINT "Reaction_replyId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "Reaction" DROP CONSTRAINT "Reaction_userId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "Reply" DROP CONSTRAINT "Reply_messageId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "Reply" DROP CONSTRAINT "Reply_senderId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "Report" DROP CONSTRAINT "Report_reportedUserId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "Report" DROP CONSTRAINT "Report_userId_fkey"; | ||
|
||
-- AlterTable | ||
ALTER TABLE "Channel" ALTER COLUMN "name" SET DATA TYPE VARCHAR(255), | ||
ALTER COLUMN "lastMessageId" SET DATA TYPE VARCHAR(255); | ||
|
||
-- AlterTable | ||
ALTER TABLE "Notification" ALTER COLUMN "token" SET DATA TYPE VARCHAR(1024), | ||
ALTER COLUMN "device" SET DATA TYPE VARCHAR(255), | ||
ALTER COLUMN "os" SET DATA TYPE VARCHAR(255), | ||
ALTER COLUMN "userId" SET DATA TYPE VARCHAR(255); | ||
|
||
-- AlterTable | ||
ALTER TABLE "Profile" ADD COLUMN "refreshToken" VARCHAR(1024), | ||
ALTER COLUMN "socialId" SET DATA TYPE VARCHAR(255); | ||
|
||
-- AlterTable | ||
ALTER TABLE "Reaction" ALTER COLUMN "value" SET DATA TYPE VARCHAR(4), | ||
ALTER COLUMN "userId" SET DATA TYPE VARCHAR(255), | ||
ALTER COLUMN "messageId" SET DATA TYPE VARCHAR(255); | ||
|
||
-- AlterTable | ||
ALTER TABLE "Reply" ALTER COLUMN "senderId" SET DATA TYPE VARCHAR(255), | ||
ALTER COLUMN "messageId" SET DATA TYPE VARCHAR(255); | ||
|
||
-- AlterTable | ||
ALTER TABLE "User" ALTER COLUMN "password" SET DATA TYPE VARCHAR(255), | ||
ALTER COLUMN "name" SET DATA TYPE VARCHAR(255), | ||
ALTER COLUMN "nickname" SET DATA TYPE VARCHAR(255), | ||
ALTER COLUMN "thumbURL" SET DATA TYPE VARCHAR(1024), | ||
ALTER COLUMN "photoURL" SET DATA TYPE VARCHAR(1024), | ||
ALTER COLUMN "phone" SET DATA TYPE VARCHAR(255); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Notification" ADD CONSTRAINT "Notification_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Profile" ADD CONSTRAINT "Profile_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Friend" ADD CONSTRAINT "Friend_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Friend" ADD CONSTRAINT "Friend_friendId_fkey" FOREIGN KEY ("friendId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "BlockedUser" ADD CONSTRAINT "BlockedUser_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "BlockedUser" ADD CONSTRAINT "BlockedUser_blockedUserId_fkey" FOREIGN KEY ("blockedUserId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Report" ADD CONSTRAINT "Report_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Report" ADD CONSTRAINT "Report_reportedUserId_fkey" FOREIGN KEY ("reportedUserId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Membership" ADD CONSTRAINT "Membership_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Membership" ADD CONSTRAINT "Membership_channelId_fkey" FOREIGN KEY ("channelId") REFERENCES "Channel"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Message" ADD CONSTRAINT "Message_channelId_fkey" FOREIGN KEY ("channelId") REFERENCES "Channel"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Message" ADD CONSTRAINT "Message_senderId_fkey" FOREIGN KEY ("senderId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Reply" ADD CONSTRAINT "Reply_senderId_fkey" FOREIGN KEY ("senderId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Reply" ADD CONSTRAINT "Reply_messageId_fkey" FOREIGN KEY ("messageId") REFERENCES "Message"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Reaction" ADD CONSTRAINT "Reaction_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Reaction" ADD CONSTRAINT "Reaction_messageId_fkey" FOREIGN KEY ("messageId") REFERENCES "Message"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Reaction" ADD CONSTRAINT "Reaction_replyId_fkey" FOREIGN KEY ("replyId") REFERENCES "Reply"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- RenameIndex | ||
ALTER INDEX "Membership.updatedAt_index" RENAME TO "Membership_updatedAt_idx"; | ||
|
||
-- RenameIndex | ||
ALTER INDEX "Notification.token_unique" RENAME TO "Notification_token_key"; | ||
|
||
-- RenameIndex | ||
ALTER INDEX "Profile.userId_unique" RENAME TO "Profile_userId_key"; | ||
|
||
-- RenameIndex | ||
ALTER INDEX "User.email_unique" RENAME TO "User_email_key"; |
Oops, something went wrong.