-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5104 from mozilla/mntor-3492
Add support for Mozilla Accounts prompt none auth flow
- Loading branch information
Showing
7 changed files
with
150 additions
and
1 deletion.
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,33 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
"use client"; | ||
|
||
import { ReactNode, useEffect } from "react"; | ||
import { useSearchParams } from "next/navigation"; | ||
import { signIn } from "next-auth/react"; | ||
import { containsExpectedSearchParams } from "../../functions/universal/attributions"; | ||
import { CONST_MOZILLA_ACCOUNTS_SETTINGS_PROMO_SEARCH_PARAMS } from "../../../constants"; | ||
|
||
export const PromptNoneAuth = (): ReactNode => { | ||
const searchParams = useSearchParams(); | ||
|
||
useEffect(() => { | ||
const isPromptNoneAuthAttempt = containsExpectedSearchParams( | ||
CONST_MOZILLA_ACCOUNTS_SETTINGS_PROMO_SEARCH_PARAMS, | ||
searchParams, | ||
); | ||
if (isPromptNoneAuthAttempt) { | ||
void signIn( | ||
"fxa", | ||
{ callbackUrl: "/user/dashboard" }, | ||
{ prompt: "none" }, | ||
); | ||
} | ||
// This effect should only run once | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
return null; | ||
}; |
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,79 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import { it, expect } from "@jest/globals"; | ||
import { containsExpectedSearchParams } from "./attributions"; | ||
|
||
it("returns `true` when the actual search params are matching the expected params", () => { | ||
expect( | ||
containsExpectedSearchParams( | ||
{ | ||
one: "1", | ||
two: "2", | ||
}, | ||
new URLSearchParams({ | ||
one: "1", | ||
two: "2", | ||
}), | ||
), | ||
).toBe(true); | ||
}); | ||
|
||
it("returns `true` when the actual search params are a superset of the expected params", () => { | ||
expect( | ||
containsExpectedSearchParams( | ||
{ | ||
one: "1", | ||
two: "2", | ||
}, | ||
new URLSearchParams({ | ||
one: "1", | ||
two: "2", | ||
three: "3", | ||
}), | ||
), | ||
).toBe(true); | ||
}); | ||
|
||
it("returns `false` if any expected param is missing from the actual search params", () => { | ||
expect( | ||
containsExpectedSearchParams( | ||
{ | ||
one: "1", | ||
two: "2", | ||
}, | ||
new URLSearchParams({ | ||
two: "2", | ||
}), | ||
), | ||
).toBe(false); | ||
}); | ||
|
||
it("returns `false` if any of the actual search param keys are not matching the expected params", () => { | ||
expect( | ||
containsExpectedSearchParams( | ||
{ | ||
one: "1", | ||
three: "2", | ||
}, | ||
new URLSearchParams({ | ||
two: "2", | ||
}), | ||
), | ||
).toBe(false); | ||
}); | ||
|
||
it("returns `false` if any of the actual search param values are not matching the expected params", () => { | ||
expect( | ||
containsExpectedSearchParams( | ||
{ | ||
one: "1", | ||
two: "3", | ||
}, | ||
new URLSearchParams({ | ||
two: "2", | ||
}), | ||
), | ||
).toBe(false); | ||
}); |
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